[#1421] Move type specific for_export code to typed champs

This commit is contained in:
Frederic Merizen 2018-06-15 14:10:25 +02:00 committed by Pierre de La Morinerie
parent ee8616fb97
commit 41734092b2
4 changed files with 19 additions and 10 deletions

View file

@ -75,16 +75,7 @@ class Champ < ApplicationRecord
def for_export
if value.present?
case type_champ
when 'textarea'
ActionView::Base.full_sanitizer.sanitize(value)
when 'yes_no'
value == 'true' ? 'oui' : 'non'
when 'multiple_drop_down_list'
drop_down_list.selected_options_without_decorator(self).join(', ')
else
value
end
value_for_export
else
nil
end
@ -117,4 +108,8 @@ class Champ < ApplicationRecord
def string_value
value.to_s
end
def value_for_export
value
end
end

View file

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

View file

@ -1,2 +1,7 @@
class Champs::TextareaChamp < Champs::TextChamp
private
def value_for_export
ActionView::Base.full_sanitizer.sanitize(value)
end
end

View file

@ -1,2 +1,7 @@
class Champs::YesNoChamp < Champs::CheckboxChamp
private
def value_for_export
value == 'true' ? 'oui' : 'non'
end
end