Module: Dustbag::Parser::Node::ClassMethods
- Defined in:
- lib/dustbag/parser/node.rb
Instance Method Summary collapse
- #child(name) ⇒ Object
- #children(*attrs) ⇒ Object
- #numeric_attributes(*attrs) ⇒ Object
- #text_attributes(*attrs) ⇒ Object
Instance Method Details
#child(name) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/dustbag/parser/node.rb', line 91 def child(name) if name.is_a? Hash define_method(name[:name]) do (name[:class] || Dustbag.const_get(name[:node])).new(subnode(name[:node])) end else node_name = xml_node_name(attr) define_method(name) do Dustbag.const_get(node_name).new(subnode(node_name)) end end end |
#children(*attrs) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/dustbag/parser/node.rb', line 72 def children(*attrs) attrs.each do |attr| if attr.is_a?(Hash) attr.each do |key, value| node_name = xml_node_name(key) define_method(key) do value.new(subnode(node_name)) end end else node_name = xml_node_name(attr) define_method(attr) do Dustbag.const_get(node_name).new(subnode(node_name)) end end end end |
#numeric_attributes(*attrs) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/dustbag/parser/node.rb', line 54 def numeric_attributes(*attrs) attrs.each do |attr| node_name = xml_node_name(attr) if attr.is_a?(Hash) attr.each do |key, value| define_method(key) do subnode_text(value).to_i end end else define_method(attr) do subnode_text(node_name).to_i end end end end |
#text_attributes(*attrs) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/dustbag/parser/node.rb', line 36 def text_attributes(*attrs) attrs.each do |attr| node_name = xml_node_name(attr) if attr.is_a?(Hash) attr.each do |key, value| define_method(key) do subnode_text(value) end end else define_method(attr) do subnode_text(node_name) end end end end |