Class: SXRB::Proxy

Inherits:
Object
  • Object
show all
Defined in:
lib/sxrb/proxy.rb

Instance Method Summary collapse

Constructor Details

#initialize(callback_tree, current_path = '') ⇒ Proxy

Returns a new instance of Proxy.


3
4
5
6
# File 'lib/sxrb/proxy.rb', line 3

def initialize(callback_tree, current_path = '')
  @callback_tree = callback_tree
  @current_path = current_path
end

Instance Method Details

#child(*args, &block) ⇒ Object


8
9
10
11
12
13
14
# File 'lib/sxrb/proxy.rb', line 8

def child(*args, &block)
  args.each do |tag|
    @callback_tree.add_rule(tag, @current_path, :recursive => false).tap do |new_path|
      block.call(Proxy.new(@callback_tree, new_path))
    end
  end
end

#descendant(*args, &block) ⇒ Object


16
17
18
19
20
21
22
# File 'lib/sxrb/proxy.rb', line 16

def descendant(*args, &block)
  args.each do |tag|
    @callback_tree.add_rule(tag, @current_path, :recursive => true).tap do |new_path|
      block.call(Proxy.new(@callback_tree, new_path))
    end
  end
end

#on_characters(&block) ⇒ Object


32
33
34
# File 'lib/sxrb/proxy.rb', line 32

def on_characters(&block)
  @callback_tree.add_callback(:characters, @current_path, &block)
end

#on_element(&block) ⇒ Object


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

def on_element(&block)
  @callback_tree.add_callback(:element, @current_path, &block)
end

#on_end(&block) ⇒ Object


36
37
38
# File 'lib/sxrb/proxy.rb', line 36

def on_end(&block)
  @callback_tree.add_callback(:end, @current_path, &block)
end

#on_start(&block) ⇒ Object


28
29
30
# File 'lib/sxrb/proxy.rb', line 28

def on_start(&block)
  @callback_tree.add_callback(:start, @current_path, &block)
end