Class: Ox::Builder::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/ox/builder/proxy.rb

Constant Summary collapse

OX_METHODS =
%W{
  value eql? attributes [] []= << text nodes alocate locate content root
}.map(&:to_sym).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ Proxy

Returns a new instance of Proxy.



21
22
23
# File 'lib/ox/builder/proxy.rb', line 21

def initialize node
  @node = node
end

Instance Attribute Details

#nodeObject (readonly)

delegate *OX_METHODS, to: :node



19
20
21
# File 'lib/ox/builder/proxy.rb', line 19

def node
  @node
end

Instance Method Details

#add_attributes(attributes) ⇒ Object



58
59
60
61
62
# File 'lib/ox/builder/proxy.rb', line 58

def add_attributes attributes
  attributes.keys.each do |attribute|
    node[attribute] = attributes[attribute]
  end
end

#cdata(content) ⇒ Object



46
47
48
49
50
# File 'lib/ox/builder/proxy.rb', line 46

def cdata content
  proxify_node(Ox::CData, content) do |proxy|
    node << proxy.node
  end
end

#comment(content) ⇒ Object



52
53
54
55
56
# File 'lib/ox/builder/proxy.rb', line 52

def comment content
  proxify_node(Ox::Comment, content) do |proxy|
    node << proxy.node
  end
end

#element(*args) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ox/builder/proxy.rb', line 25

def element *args
  attributes = args.extract_options!
  name = args.shift

  proxify_node(Ox::Element, name) do |proxy|
    proxy.add_attributes(attributes)
    args.each do |text|
      proxy.node << text.to_s if text.respond_to?(:to_s)
    end
    yield proxy if block_given?
    node << proxy.node
  end
end

#instruct(name, attributes = {}) ⇒ Object



39
40
41
42
43
44
# File 'lib/ox/builder/proxy.rb', line 39

def instruct name, attributes = {}
  proxify_node(Ox::Instruct, name) do |proxy|
    proxy.add_attributes(attributes)
    node << proxy.node
  end
end

#to_sObject



64
65
66
# File 'lib/ox/builder/proxy.rb', line 64

def to_s
  Ox.dump(node)
end