Class: Parser::XMLBuilderEngine

Inherits:
Object
  • Object
show all
Defined in:
lib/kuniri/parser/xml_builder_engine.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pBaseSpaceIdent = 2) ⇒ XMLBuilderEngine

Returns a new instance of XMLBuilderEngine.



12
13
14
# File 'lib/kuniri/parser/xml_builder_engine.rb', line 12

def initialize(pBaseSpaceIdent = 2)
  set_default(pBaseSpaceIdent)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(pTagName, *pTagParameters, &pBlock) ⇒ Object (private)



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/kuniri/parser/xml_builder_engine.rb', line 35

def method_missing(pTagName, *pTagParameters, &pBlock)
  @tag += "\n" unless @tag.strip == ''
  currentTagName = "#{@ident}<#{pTagName.to_s}"
  @tag << currentTagName
  if pTagParameters.size > 0 and pTagParameters[0].is_a? Hash
    handleArguments(pTagParameters)
  end

  if block_given?
    @tag << ">\n"
    incrementIdentation
    result = instance_eval(&pBlock)
    if result != '' && result.is_a?(String)
      updateTag(result)
    end

    decrementIdent
    @tag << "#{@ident}</#{pTagName.to_s}>\n"
    @tag.squeeze!("\n")
  else
    @tag << "/>\n"
  end
    @content = ''
end

Instance Attribute Details

#betweenTagObject (readonly)

Returns the value of attribute betweenTag.



6
7
8
# File 'lib/kuniri/parser/xml_builder_engine.rb', line 6

def betweenTag
  @betweenTag
end

#identObject (readonly)

Returns the value of attribute ident.



7
8
9
# File 'lib/kuniri/parser/xml_builder_engine.rb', line 7

def ident
  @ident
end

#identIncrementObject

Returns the value of attribute identIncrement.



8
9
10
# File 'lib/kuniri/parser/xml_builder_engine.rb', line 8

def identIncrement
  @identIncrement
end

#tagObject (readonly)

Returns the value of attribute tag.



5
6
7
# File 'lib/kuniri/parser/xml_builder_engine.rb', line 5

def tag
  @tag
end

Instance Method Details

#reset_engineObject



20
21
22
23
# File 'lib/kuniri/parser/xml_builder_engine.rb', line 20

def reset_engine
  @tag = nil
  set_default
end

#set_default(pBaseSpaceIdent = 2) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/kuniri/parser/xml_builder_engine.rb', line 25

def set_default(pBaseSpaceIdent = 2)
  @tag = '<?xml version="1.0" encoding="UTF-8"?>'
  @baseSpaceIdentation = pBaseSpaceIdent
  @content = ''
  @ident = ''
  @identIncrement = ' ' * pBaseSpaceIdent
end

#to_xmlObject



16
17
18
# File 'lib/kuniri/parser/xml_builder_engine.rb', line 16

def to_xml
  return @tag
end