Class: Ox::Builder::Factory

Inherits:
Object
  • Object
show all
Includes:
DSL
Defined in:
lib/ox/builder/factory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DSL

#cdata!, #comment!, #doctype!, #instruct!, #tag!

Constructor Details

#initialize(node) ⇒ Factory

Returns a new instance of Factory.



8
9
10
# File 'lib/ox/builder/factory.rb', line 8

def initialize(node)
  @node = node
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object (protected)



31
32
33
34
# File 'lib/ox/builder/factory.rb', line 31

def method_missing(name, *args, &block)
  name = name[0...-1] if name.to_s.end_with?('!')
  tag!(name, *args, &block)
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



6
7
8
# File 'lib/ox/builder/factory.rb', line 6

def node
  @node
end

Instance Method Details

#add_attributes(attributes) ⇒ Object



23
24
25
26
27
# File 'lib/ox/builder/factory.rb', line 23

def add_attributes(attributes)
  attributes.each do |key, val|
    node[key] = val
  end
end

#inspectObject



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

def inspect
  "#<#{self.class.name}:0x#{"%x" % object_id} node=#{node}>"
end

#to_s(options = {}) ⇒ Object Also known as: to_xml



12
13
14
15
16
# File 'lib/ox/builder/factory.rb', line 12

def to_s(options = {})
  encoding = options.fetch(:encoding, 'UTF-8')
  indent = options.fetch(:indent, 2)
  Ox.dump(node, encoding: encoding, indent: indent)
end