Class: Duxml::Saxer::DocuLiner

Inherits:
Ox::Sax
  • Object
show all
Defined in:
lib/duxml/saxer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(doc, _observer) ⇒ DocuLiner

Returns a new instance of DocuLiner.

Parameters:

  • doc (Ox::Document)

    document that is being constructed as XML is parsed

  • _observer (Object)

    object that will observe this document’s content



25
26
27
28
29
30
# File 'lib/duxml/saxer.rb', line 25

def initialize(doc, _observer)
  @cursor_stack = [doc]
  @line = 0
  @column = 0
  @observer = _observer
end

Instance Attribute Details

#columnObject (readonly)

Returns the value of attribute column.



32
33
34
# File 'lib/duxml/saxer.rb', line 32

def column
  @column
end

#cursor_stackObject

Returns the value of attribute cursor_stack.



38
39
40
# File 'lib/duxml/saxer.rb', line 38

def cursor_stack
  @cursor_stack
end

#lineObject (readonly)

Returns the value of attribute line.



32
33
34
# File 'lib/duxml/saxer.rb', line 32

def line
  @line
end

#observerObject (readonly)

Returns the value of attribute observer.



32
33
34
# File 'lib/duxml/saxer.rb', line 32

def observer
  @observer
end

Instance Method Details

#attr(name, val) ⇒ Object



45
46
47
# File 'lib/duxml/saxer.rb', line 45

def attr(name, val)
  cursor[name] = val
end

#cursorObject



34
35
36
# File 'lib/duxml/saxer.rb', line 34

def cursor
  cursor_stack.last
end

#end_element(name) ⇒ Object



53
54
55
56
# File 'lib/duxml/saxer.rb', line 53

def end_element(name)
  cursor.add_observer(observer) if observer
  @cursor_stack.pop
end

#start_element(name) ⇒ Object



40
41
42
43
# File 'lib/duxml/saxer.rb', line 40

def start_element(name)
  cursor.nodes.insert(-1, Duxml::Element.new(name, line, column))
  cursor_stack << cursor.nodes.last
end

#text(str) ⇒ Object



49
50
51
# File 'lib/duxml/saxer.rb', line 49

def text(str)
  cursor.nodes.insert(-1, str)
end