Class: Ox::Builder::Proxy
- Inherits:
-
Object
- Object
- Ox::Builder::Proxy
- 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
-
#node ⇒ Object
readonly
delegate *OX_METHODS, to: :node.
Instance Method Summary collapse
- #add_attributes(attributes) ⇒ Object
- #cdata(content) ⇒ Object
- #comment(content) ⇒ Object
- #element(*args) ⇒ Object
-
#initialize(node) ⇒ Proxy
constructor
A new instance of Proxy.
- #instruct(name, attributes = {}) ⇒ Object
- #to_s ⇒ Object
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
#node ⇒ Object (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. 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_s ⇒ Object
64 65 66 |
# File 'lib/ox/builder/proxy.rb', line 64 def to_s Ox.dump(node) end |