Class: Nokogireader::ReadData
- Inherits:
-
Object
- Object
- Nokogireader::ReadData
- Defined in:
- lib/nokogireader/read_data.rb
Instance Attribute Summary collapse
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#text ⇒ Object
Returns the value of attribute text.
Instance Method Summary collapse
- #[](child_name) ⇒ Object
- #add_child(definition, node) ⇒ Object
- #attributes ⇒ Object
- #children ⇒ Object
- #clear_child_for(node) ⇒ Object
-
#initialize(parent_data, definition, node) ⇒ ReadData
constructor
A new instance of ReadData.
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
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
4 5 6 |
# File 'lib/nokogireader/read_data.rb', line 4 def parent @parent end |
#text ⇒ Object
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 |
#attributes ⇒ Object
14 15 16 |
# File 'lib/nokogireader/read_data.rb', line 14 def attributes @attributes ||= {} end |
#children ⇒ Object
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 |