Class: ReVIEW::EPUBMaker::ReVIEWHeaderListener
- Includes:
- REXML::StreamListener
- Defined in:
- lib/review/epubmaker/reviewheaderlistener.rb
Instance Method Summary collapse
-
#initialize(headlines) ⇒ ReVIEWHeaderListener
constructor
A new instance of ReVIEWHeaderListener.
- #tag_end(name) ⇒ Object
- #tag_start(name, attrs) ⇒ Object
- #text(text) ⇒ Object
Constructor Details
#initialize(headlines) ⇒ ReVIEWHeaderListener
Returns a new instance of ReVIEWHeaderListener.
12 13 14 15 16 |
# File 'lib/review/epubmaker/reviewheaderlistener.rb', line 12 def initialize(headlines) @level = nil @content = '' @headlines = headlines end |
Instance Method Details
#tag_end(name) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/review/epubmaker/reviewheaderlistener.rb', line 33 def tag_end(name) if name =~ /\Ah\d+/ if @id.present? @headlines.push({ 'level' => @level, 'id' => @id, 'title' => @content, 'notoc' => @notoc }) end @content = '' @level = nil @id = nil @notoc = nil end true end |
#tag_start(name, attrs) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/review/epubmaker/reviewheaderlistener.rb', line 18 def tag_start(name, attrs) if name =~ /\Ah(\d+)/ raise "#{name}, #{attrs}" if @level.present? @level = $1.to_i @id = attrs['id'] if attrs['id'].present? @notoc = attrs['notoc'] if attrs['notoc'].present? elsif !@level.nil? if name == 'img' && attrs['alt'].present? @content << attrs['alt'] elsif name == 'a' && attrs['id'].present? @id = attrs['id'] end end end |
#text(text) ⇒ Object
50 51 52 53 54 |
# File 'lib/review/epubmaker/reviewheaderlistener.rb', line 50 def text(text) if @level.present? @content << text.gsub("\t", ' ') end end |