Class: ReVIEW::EPUBMaker::ReVIEWHeaderListener

Inherits:
Object
  • Object
show all
Includes:
REXML::StreamListener
Defined in:
lib/review/epubmaker.rb

Instance Method Summary collapse

Constructor Details

#initialize(headlines) ⇒ ReVIEWHeaderListener

Returns a new instance of ReVIEWHeaderListener.



506
507
508
509
510
# File 'lib/review/epubmaker.rb', line 506

def initialize(headlines)
  @level = nil
  @content = ''
  @headlines = headlines
end

Instance Method Details

#tag_end(name) ⇒ Object



527
528
529
530
531
532
533
534
535
536
537
# File 'lib/review/epubmaker.rb', line 527

def tag_end(name)
  if name =~ /\Ah\d+/
    @headlines.push({ 'level' => @level, 'id' => @id, 'title' => @content, 'notoc' => @notoc }) if @id.present?
    @content = ''
    @level = nil
    @id = nil
    @notoc = nil
  end

  true
end

#tag_start(name, attrs) ⇒ Object



512
513
514
515
516
517
518
519
520
521
522
523
524
525
# File 'lib/review/epubmaker.rb', line 512

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



539
540
541
# File 'lib/review/epubmaker.rb', line 539

def text(text)
  @content << text.gsub("\t", ' ') if @level.present?
end