[#1421] Move type specific to_s implementations to typed champs

This commit is contained in:
Frederic Merizen 2018-06-15 13:47:32 +02:00 committed by Pierre de La Morinerie
parent c2f199c5aa
commit ee8616fb97
3 changed files with 15 additions and 8 deletions

View file

@ -67,14 +67,7 @@ class Champ < ApplicationRecord
def to_s
if value.present?
case type_champ
when 'date'
Date.parse(value).strftime('%d/%m/%Y')
when 'multiple_drop_down_list'
drop_down_list.selected_options_without_decorator(self).join(', ')
else
value.to_s
end
string_value
else
''
end
@ -118,4 +111,10 @@ class Champ < ApplicationRecord
errors
end
private
def string_value
value.to_s
end
end

View file

@ -11,4 +11,8 @@ class Champs::DateChamp < Champ
nil
end
end
def string_value
Date.parse(value).strftime('%d/%m/%Y')
end
end

View file

@ -14,4 +14,8 @@ class Champs::MultipleDropDownListChamp < Champ
end
end
end
def string_value
drop_down_list.selected_options_without_decorator(self).join(', ')
end
end