Class: PolyrexObjects::PolyrexObject
- Inherits:
-
Object
- Object
- PolyrexObjects::PolyrexObject
- Defined in:
- lib/polyrex-objects.rb
Instance Attribute Summary collapse
-
#node ⇒ Object
readonly
Returns the value of attribute node.
Instance Method Summary collapse
- #add(pxobj) ⇒ Object
- #clone ⇒ Object
- #create(id = nil) ⇒ Object
- #delete ⇒ Object
- #element(xpath) ⇒ Object
-
#initialize(node, id = '0') ⇒ PolyrexObject
constructor
A new instance of PolyrexObject.
- #inspect ⇒ Object
- #to_h ⇒ Object
- #to_xml(options = {}) ⇒ Object
- #with {|_self| ... } ⇒ Object
- #xpath(s) ⇒ Object
Constructor Details
#initialize(node, id = '0') ⇒ PolyrexObject
Returns a new instance of PolyrexObject.
16 17 18 19 20 |
# File 'lib/polyrex-objects.rb', line 16 def initialize(node, id='0') @@id = id @node = node @fields =[] end |
Instance Attribute Details
#node ⇒ Object (readonly)
Returns the value of attribute node.
14 15 16 |
# File 'lib/polyrex-objects.rb', line 14 def node @node end |
Instance Method Details
#add(pxobj) ⇒ Object
22 23 24 |
# File 'lib/polyrex-objects.rb', line 22 def add(pxobj) @node.element('records').add pxobj.node end |
#clone ⇒ Object
26 27 28 |
# File 'lib/polyrex-objects.rb', line 26 def clone() self.class.new Rexle.new(self.node.to_a).root end |
#create(id = nil) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/polyrex-objects.rb', line 30 def create(id=nil) id ||= @@id id.succ! @create.id = id @create.record = @node.element('records') @create end |
#delete ⇒ Object
39 40 41 |
# File 'lib/polyrex-objects.rb', line 39 def delete() @node.delete end |
#element(xpath) ⇒ Object
43 44 45 |
# File 'lib/polyrex-objects.rb', line 43 def element(xpath) @node.element(xpath) end |
#inspect ⇒ Object
47 48 49 |
# File 'lib/polyrex-objects.rb', line 47 def inspect() "#<PolyrexObject:%s" % __id__ end |
#to_h ⇒ Object
51 52 53 54 55 |
# File 'lib/polyrex-objects.rb', line 51 def to_h() @fields.inject({}) do |r, field| r.merge(field => self.method(field).call) end end |
#to_xml(options = {}) ⇒ Object
57 58 59 |
# File 'lib/polyrex-objects.rb', line 57 def to_xml(={}) @node.xml() end |
#with {|_self| ... } ⇒ Object
61 62 63 |
# File 'lib/polyrex-objects.rb', line 61 def with() yield(self) end |
#xpath(s) ⇒ Object
65 66 67 |
# File 'lib/polyrex-objects.rb', line 65 def xpath(s) @node.xpath(s) end |