Class: Ninetails::ElementDefinition
- Inherits:
-
Object
- Object
- Ninetails::ElementDefinition
- Defined in:
- app/components/ninetails/element_definition.rb
Instance Attribute Summary collapse
-
#count ⇒ Object
Returns the value of attribute count.
-
#elements ⇒ Object
Returns the value of attribute elements.
-
#name ⇒ Object
Returns the value of attribute name.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #add_to_hash(hash) ⇒ Object
- #all_elements_valid? ⇒ Boolean
- #deserialize(input) ⇒ Object
-
#initialize(name, type, count) ⇒ ElementDefinition
constructor
A new instance of ElementDefinition.
- #properties_structure ⇒ Object
Constructor Details
#initialize(name, type, count) ⇒ ElementDefinition
Returns a new instance of ElementDefinition.
7 8 9 10 11 12 |
# File 'app/components/ninetails/element_definition.rb', line 7 def initialize(name, type, count) @name = name @type = type @count = count @elements = [] end |
Instance Attribute Details
#count ⇒ Object
Returns the value of attribute count.
3 4 5 |
# File 'app/components/ninetails/element_definition.rb', line 3 def count @count end |
#elements ⇒ Object
Returns the value of attribute elements.
3 4 5 |
# File 'app/components/ninetails/element_definition.rb', line 3 def elements @elements end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'app/components/ninetails/element_definition.rb', line 3 def name @name end |
#type ⇒ Object
Returns the value of attribute type.
3 4 5 |
# File 'app/components/ninetails/element_definition.rb', line 3 def type @type end |
Instance Method Details
#add_to_hash(hash) ⇒ Object
14 15 16 17 18 19 20 |
# File 'app/components/ninetails/element_definition.rb', line 14 def add_to_hash(hash) if count == :single hash[name] = single_element_structure else hash[name] = multiple_element_structure end end |
#all_elements_valid? ⇒ Boolean
38 39 40 |
# File 'app/components/ninetails/element_definition.rb', line 38 def all_elements_valid? elements.all?(&:valid?) end |
#deserialize(input) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/components/ninetails/element_definition.rb', line 22 def deserialize(input) self.elements = [] if input.is_a? Array input.each do |hash| add_element hash end else add_element input end end |
#properties_structure ⇒ Object
34 35 36 |
# File 'app/components/ninetails/element_definition.rb', line 34 def properties_structure @properties_structure ||= type.new.properties_structure end |