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



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

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

Instance Attribute Details

#column ⇒ Object (readonly)

Returns the value of attribute column.



36
37
38
# File 'lib/duxml/saxer.rb', line 36

def column
  @column
end

#cursor_stack ⇒ Object

Returns the value of attribute cursor_stack.



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

def cursor_stack
  @cursor_stack
end

#line ⇒ Object (readonly)

Returns the value of attribute line.



36
37
38
# File 'lib/duxml/saxer.rb', line 36

def line
  @line
end

#observer ⇒ Object (readonly)

Returns the value of attribute observer.



36
37
38
# File 'lib/duxml/saxer.rb', line 36

def observer
  @observer
end

Instance Method Details

#attr(name, val) ⇒ Object



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

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

#cursor ⇒ Object



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

def cursor
  cursor_stack.last
end

#end_element(name) ⇒ Object



57
58
59
60
# File 'lib/duxml/saxer.rb', line 57

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

#start_element(name) ⇒ Object



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

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

#text(str) ⇒ Object



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

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