Class: Nokogireader::ReadData

Inherits:
Object
  • Object
show all
Defined in:
lib/nokogireader/read_data.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent_data, definition, node) ⇒ ReadData

Returns a new instance of ReadData.



6
7
8
9
10
11
12
# File 'lib/nokogireader/read_data.rb', line 6

def initialize(parent_data, definition, node)
  @parent = parent_data
  @definition = definition
  @definition.read_attributes.each do |a|
    attributes[a] = node.attribute(a.to_s)
  end
end

Instance Attribute Details

#parentObject (readonly)

Returns the value of attribute parent.



4
5
6
# File 'lib/nokogireader/read_data.rb', line 4

def parent
  @parent
end

#textObject

Returns the value of attribute text.



3
4
5
# File 'lib/nokogireader/read_data.rb', line 3

def text
  @text
end

Instance Method Details

#[](child_name) ⇒ Object



40
41
42
# File 'lib/nokogireader/read_data.rb', line 40

def [](child_name)
  children[child_name.to_s]
end

#add_child(definition, node) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/nokogireader/read_data.rb', line 22

def add_child(definition, node)
  child = self.class.new(self, definition, node)
  if definition.multiple?
    (children[node.name] ||= []) << child
  else
    children[node.name] = child
  end
  child
end

#attributesObject



14
15
16
# File 'lib/nokogireader/read_data.rb', line 14

def attributes
  @attributes ||= {}
end

#childrenObject



18
19
20
# File 'lib/nokogireader/read_data.rb', line 18

def children
  @children ||= {}
end

#clear_child_for(node) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/nokogireader/read_data.rb', line 32

def clear_child_for(node)
  if children[node.name].is_a?(Array)
    children[node.name].pop
  else
    children.delete(node.name)
  end
end