Class: ReDuxml::ResolverClass

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

Constant Summary collapse

COND_ATTR_NAME =
'if'
REF_ATTR_NAME =
'ref'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logic) ⇒ ResolverClass

Returns a new instance of ResolverClass.

Parameters:

  • doc (Ox::Document)

    document that is being constructed as XML is parsed

  • _observer (Object)

    object that will observe this document’s content



19
20
21
22
# File 'lib/re_dux.rb', line 19

def initialize(logic)
  @cursor_stack = []
  @e = ReDuxml::Evaluator.new(logic)
end

Instance Attribute Details

#cursor_stackObject (readonly)

Returns the value of attribute cursor_stack.



15
16
17
# File 'lib/re_dux.rb', line 15

def cursor_stack
  @cursor_stack
end

#deadObject (readonly)

Returns the value of attribute dead.



15
16
17
# File 'lib/re_dux.rb', line 15

def dead
  @dead
end

#eObject (readonly)

Returns the value of attribute e.



15
16
17
# File 'lib/re_dux.rb', line 15

def e
  @e
end

Instance Method Details

#attr(name, val) ⇒ Object



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

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

#cursorObject



24
25
26
# File 'lib/re_dux.rb', line 24

def cursor
  @cursor_stack.last
end

#end_element(name) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/re_dux.rb', line 42

def end_element(name)
  case
    when cursor.if?
      cursor.remove_attribute(COND_ATTR_NAME)
    when cursor.respond_to?(:instantiate)
      # target = cursor.instantiate # target likely plural
      @cursor_stack[-2].replace(cursor, target)
    when cursor.ref?
      # target = resolve_ref
      @cursor_stack[-2].replace(cursor, target)
      cursor.remove_attribute(REF_ATTR_NAME)
    else
      @cursor_stack[-2].remove(cursor)
      return
  end
  @cursor_stack.pop
end

#start_element(name) ⇒ Object



28
29
30
31
32
# File 'lib/re_dux.rb', line 28

def start_element(name)
  new_el = Duxml::Element.new(name, line, column)
  cursor << new_el unless cursor.nil?
  @cursor_stack << new_el
end

#text(str) ⇒ Object



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

def text(str)
  cursor << str
end