Class: PolyrexObjects::PolyrexObject

Inherits:
Object
  • Object
show all
Defined in:
lib/polyrex-objects.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nodeObject (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

#cloneObject



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

#deleteObject



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

#inspectObject



47
48
49
# File 'lib/polyrex-objects.rb', line 47

def inspect()
  "#<PolyrexObject:%s" % __id__
end

#to_hObject



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(options={})
  @node.xml(options)
end

#with {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



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