Class: Cheepub::HeadingParser::Handler
- Inherits:
-
Object
- Object
- Cheepub::HeadingParser::Handler
- Defined in:
- lib/cheepub/heading_parser/handler.rb
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
- #after_element(ns, name) ⇒ Object
-
#initialize(filename) ⇒ Handler
constructor
A new instance of Handler.
- #on_element(ns, name, attrs) ⇒ Object
- #on_text(text) ⇒ Object
Constructor Details
#initialize(filename) ⇒ Handler
Returns a new instance of Handler.
7 8 9 10 11 |
# File 'lib/cheepub/heading_parser/handler.rb', line 7 def initialize(filename) @filename = filename @stack = [] @result = [] end |
Instance Attribute Details
#result ⇒ Object (readonly)
Returns the value of attribute result.
5 6 7 |
# File 'lib/cheepub/heading_parser/handler.rb', line 5 def result @result end |
Instance Method Details
#after_element(ns, name) ⇒ Object
25 26 27 28 |
# File 'lib/cheepub/heading_parser/handler.rb', line 25 def after_element(ns, name) return if @stack.empty? @result.push(@stack.pop) end |
#on_element(ns, name, attrs) ⇒ Object
13 14 15 16 17 |
# File 'lib/cheepub/heading_parser/handler.rb', line 13 def on_element(ns, name, attrs) if name =~ /^h([1-6])/i @stack.push({filename: @filename, name: name, level: $1.to_i, content: "", id: attrs["id"]}) end end |
#on_text(text) ⇒ Object
19 20 21 22 23 |
# File 'lib/cheepub/heading_parser/handler.rb', line 19 def on_text(text) last_elem = @stack[-1] return if !last_elem last_elem[:content] = last_elem[:content]+text end |