Class: Verku::Stream
- Inherits:
-
Object
- Object
- Verku::Stream
- Defined in:
- lib/verku/stream.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#html ⇒ Object
readonly
Returns the value of attribute html.
-
#listener ⇒ Object
Returns the value of attribute listener.
Instance Method Summary collapse
- #emit(node) ⇒ Object
-
#initialize(content, listener) ⇒ Stream
constructor
A new instance of Stream.
- #parse ⇒ Object
- #traverse(node) ⇒ Object
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
#content ⇒ Object
Returns the value of attribute content.
3 4 5 |
# File 'lib/verku/stream.rb', line 3 def content @content end |
#html ⇒ Object (readonly)
Returns the value of attribute html.
4 5 6 |
# File 'lib/verku/stream.rb', line 4 def html @html end |
#listener ⇒ Object
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 |
#parse ⇒ Object
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 |