Class: RXSD::XML::Node
- Inherits:
-
Object
- Object
- RXSD::XML::Node
- Defined in:
- lib/rxsd/xml.rb,
lib/rxsd/libxml_adapter.rb
Overview
RXSD XML node interface that subclasses must conform to and implement methods
Direct Known Subclasses
Instance Attribute Summary collapse
-
#related ⇒ Object
Provides accessor interface to related obj, in our case related xsd obj.
Class Method Summary collapse
-
.factory(args = {}) ⇒ Object
Node factory, returns root node corresponding to specified backend and xml data.
Instance Method Summary collapse
-
#child_obj(klass) ⇒ Object
Instantiate first child of provided class type.
-
#child_value(tag_name) ⇒ Object
Return ‘value’ attribute of first childw/ specified tag.
-
#child_values(tag_name) ⇒ Object
Return ‘value’ attribute of all children w/ specified tag.
-
#children_objs(klass) ⇒ Object
Instantiate all children of provided class type.
-
#root ⇒ Object
Returns root node.
Instance Attribute Details
#related ⇒ Object
Provides accessor interface to related obj, in our case related xsd obj
62 63 64 |
# File 'lib/rxsd/xml.rb', line 62 def end |
Class Method Details
.factory(args = {}) ⇒ Object
Node factory, returns root node corresponding to specified backend and xml data
47 48 49 50 51 52 53 54 |
# File 'lib/rxsd/xml.rb', line 47 def self.factory(args = {}) backend = args[:backend] xml = args[:xml] # add additional backend drivers here if desired return LibXMLNode.xml_root(xml) if backend == :libxml return nil end |
Instance Method Details
#child_obj(klass) ⇒ Object
Instantiate first child of provided class type
74 75 76 |
# File 'lib/rxsd/xml.rb', line 74 def child_obj(klass) return children_objs(klass)[0] end |
#child_value(tag_name) ⇒ Object
Return ‘value’ attribute of first childw/ specified tag
86 87 88 |
# File 'lib/rxsd/xml.rb', line 86 def child_value(tag_name) return child_values(tag_name)[0] end |
#child_values(tag_name) ⇒ Object
Return ‘value’ attribute of all children w/ specified tag
79 80 81 82 83 |
# File 'lib/rxsd/xml.rb', line 79 def child_values(tag_name) values = [] children.find_all { |c| c.name == tag_name }.each { |c| values.push(c.attrs['value']) } return values end |
#children_objs(klass) ⇒ Object
Instantiate all children of provided class type
65 66 67 68 69 70 71 |
# File 'lib/rxsd/xml.rb', line 65 def children_objs(klass) elements = [] children.find_all { |c| c.name == klass.tag_name }.each { |c| elements << klass.from_xml(c) } return elements end |
#root ⇒ Object
Returns root node
57 58 59 |
# File 'lib/rxsd/xml.rb', line 57 def root parent? ? parent.root : self end |