Mutualize code in methods
As done in YesNoChamp
This commit is contained in:
parent
866c74ce63
commit
0846bad1c8
2 changed files with 14 additions and 2 deletions
|
@ -2,10 +2,16 @@ class Champs::DecimalNumberChamp < Champ
|
|||
validates :value, numericality: { allow_nil: true, allow_blank: true }
|
||||
|
||||
def for_export
|
||||
value.present? ? value.to_f : nil
|
||||
processed_value
|
||||
end
|
||||
|
||||
def for_api
|
||||
processed_value
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def processed_value
|
||||
value.present? ? value.to_f : nil
|
||||
end
|
||||
end
|
||||
|
|
|
@ -2,10 +2,16 @@ class Champs::IntegerNumberChamp < Champ
|
|||
validates :value, numericality: { only_integer: true, allow_nil: true, allow_blank: true }
|
||||
|
||||
def for_export
|
||||
value.present? ? value.to_i : nil
|
||||
processed_value
|
||||
end
|
||||
|
||||
def for_api
|
||||
processed_value
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def processed_value
|
||||
value.present? ? value.to_i : nil
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue