Class: Decidim::DecidimAwesome::CustomFields
- Inherits:
-
Object
- Object
- Decidim::DecidimAwesome::CustomFields
- Defined in:
- lib/decidim/decidim_awesome/custom_fields.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#fields ⇒ Object
readonly
Returns the value of attribute fields.
-
#xml ⇒ Object
readonly
Returns the value of attribute xml.
Instance Method Summary collapse
- #apply_xml(xml) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(fields) ⇒ CustomFields
constructor
A new instance of CustomFields.
- #present? ⇒ Boolean
- #to_json(*_args) ⇒ Object
- #translate! ⇒ Object
Constructor Details
#initialize(fields) ⇒ CustomFields
Returns a new instance of CustomFields.
6 7 8 9 10 11 12 |
# File 'lib/decidim/decidim_awesome/custom_fields.rb', line 6 def initialize(fields) @fields = if fields.respond_to? :map fields.map { |f| JSON.parse(f) }.flatten else JSON.parse(fields) end end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
14 15 16 |
# File 'lib/decidim/decidim_awesome/custom_fields.rb', line 14 def data @data end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
14 15 16 |
# File 'lib/decidim/decidim_awesome/custom_fields.rb', line 14 def errors @errors end |
#fields ⇒ Object (readonly)
Returns the value of attribute fields.
14 15 16 |
# File 'lib/decidim/decidim_awesome/custom_fields.rb', line 14 def fields @fields end |
#xml ⇒ Object (readonly)
Returns the value of attribute xml.
14 15 16 |
# File 'lib/decidim/decidim_awesome/custom_fields.rb', line 14 def xml @xml end |
Instance Method Details
#apply_xml(xml) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/decidim/decidim_awesome/custom_fields.rb', line 24 def apply_xml(xml) parse_xml(xml) map_fields! rescue StandardError => e @errors = e. end |
#empty? ⇒ Boolean
16 17 18 |
# File 'lib/decidim/decidim_awesome/custom_fields.rb', line 16 def empty? @fields.empty? end |
#present? ⇒ Boolean
20 21 22 |
# File 'lib/decidim/decidim_awesome/custom_fields.rb', line 20 def present? !@fields.empty? end |
#to_json(*_args) ⇒ Object
31 32 33 |
# File 'lib/decidim/decidim_awesome/custom_fields.rb', line 31 def to_json(*_args) @fields end |
#translate! ⇒ Object
35 36 37 |
# File 'lib/decidim/decidim_awesome/custom_fields.rb', line 35 def translate! translate_values! end |