Class: FN::Node::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/fn/node/context.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeContext

Returns a new instance of Context.



11
12
13
14
# File 'lib/fn/node/context.rb', line 11

def initialize
  @doc = XML::Document.new
  @doc.root = @current = FN::Node::Root()
end

Instance Attribute Details

#currentObject

Returns the value of attribute current.



9
10
11
# File 'lib/fn/node/context.rb', line 9

def current
  @current
end

#docObject (readonly)

Returns the value of attribute doc.



8
9
10
# File 'lib/fn/node/context.rb', line 8

def doc
  @doc
end

Instance Method Details

#<<(node) ⇒ Object



16
17
18
19
# File 'lib/fn/node/context.rb', line 16

def <<(node)
  add node
  @current = node
end

#add(node) ⇒ Object



29
30
31
# File 'lib/fn/node/context.rb', line 29

def add(node)
  @current << node
end

#inject_at_head(item) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/fn/node/context.rb', line 52

def inject_at_head(item)
  head = @doc.find_first("//begin_document")
  if head.first? 
    head.first.prev = item
  else
    head << item
  end
end

#inject_at_page(number) {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



61
62
63
64
65
66
67
# File 'lib/fn/node/context.rb', line 61

def inject_at_page(number)
  old = @current
  @current = @doc.find_first("//begin_page_ext[@number='#{number}']") or 
             raise "page not found: #{number}.  Pages: #{@doc.find('//begin_page_ext').map{|n|n.to_s}.inspect}"
  yield self
  @current = old
end

#pre(item) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/fn/node/context.rb', line 44

def pre(item)
  if @current.first? 
    @current.first.prev = item
  else
    @current << item
  end
end

#retain_after {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



33
34
35
36
37
# File 'lib/fn/node/context.rb', line 33

def retain_after
  old = @current
  yield self
  @current = old
end

#rootObject



21
22
23
# File 'lib/fn/node/context.rb', line 21

def root
  doc.root
end

#root?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/fn/node/context.rb', line 25

def root?
  current == root
end

#visit(struct, debug = false) ⇒ Object



39
40
41
42
# File 'lib/fn/node/context.rb', line 39

def visit(struct, debug = false)
  root.visit(struct,debug)
  struct
end