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



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.message
end

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?
  @fields.empty?
end

#present?Boolean

Returns:

  • (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