Class: Decidim::DecidimAwesome::CustomFields

Inherits:
Object
  • Object
show all
Defined in:
lib/decidim/decidim_awesome/custom_fields.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dataObject (readonly)

Returns the value of attribute data.



14
15
16
# File 'lib/decidim/decidim_awesome/custom_fields.rb', line 14

def data
  @data
end

#errorsObject (readonly)

Returns the value of attribute errors.



14
15
16
# File 'lib/decidim/decidim_awesome/custom_fields.rb', line 14

def errors
  @errors
end

#fieldsObject (readonly)

Returns the value of attribute fields.



14
15
16
# File 'lib/decidim/decidim_awesome/custom_fields.rb', line 14

def fields
  @fields
end

#xmlObject (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



16
17
18
19
20
21
# File 'lib/decidim/decidim_awesome/custom_fields.rb', line 16

def apply_xml(xml)
  parse_xml(xml)
  map_fields!
rescue StandardError => e
  @errors = e.message
end

#to_json(*_args) ⇒ Object



23
24
25
# File 'lib/decidim/decidim_awesome/custom_fields.rb', line 23

def to_json(*_args)
  @fields
end

#translate!Object



27
28
29
# File 'lib/decidim/decidim_awesome/custom_fields.rb', line 27

def translate!
  translate_values!
end