Class: Ninetails::ElementDefinition

Inherits:
Object
  • Object
show all
Defined in:
app/components/ninetails/element_definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#countObject

Returns the value of attribute count.



3
4
5
# File 'app/components/ninetails/element_definition.rb', line 3

def count
  @count
end

#elementsObject

Returns the value of attribute elements.



3
4
5
# File 'app/components/ninetails/element_definition.rb', line 3

def elements
  @elements
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'app/components/ninetails/element_definition.rb', line 3

def name
  @name
end

#typeObject

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

Returns:

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



34
35
36
# File 'app/components/ninetails/element_definition.rb', line 34

def properties_structure
  @properties_structure ||= type.new.properties_structure
end