Class: Verku::Stream

Inherits:
Object
  • Object
show all
Defined in:
lib/verku/stream.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content, listener) ⇒ Stream

Returns a new instance of Stream.


6
7
8
9
10
# File 'lib/verku/stream.rb', line 6

def initialize(content, listener)
  @content  = content
  @listener = listener
  @html = Nokogiri::HTML.parse(content)
end

Instance Attribute Details

#contentObject

Returns the value of attribute content


3
4
5
# File 'lib/verku/stream.rb', line 3

def content
  @content
end

#htmlObject (readonly)

Returns the value of attribute html


4
5
6
# File 'lib/verku/stream.rb', line 4

def html
  @html
end

#listenerObject

Returns the value of attribute listener


3
4
5
# File 'lib/verku/stream.rb', line 3

def listener
  @listener
end

Instance Method Details

#emit(node) ⇒ Object


23
24
25
# File 'lib/verku/stream.rb', line 23

def emit(node)
  listener.send(:tag, node) if node.name =~ /h[1-6]/
end

#parseObject


12
13
14
# File 'lib/verku/stream.rb', line 12

def parse
  traverse(html)
end

#traverse(node) ⇒ Object


16
17
18
19
20
21
# File 'lib/verku/stream.rb', line 16

def traverse(node)
  node.children.each do |child|
    emit(child)
    traverse(child)
  end
end