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.



494
495
496
497
498
# File 'lib/review/epubmaker.rb', line 494

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

Instance Method Details

#tag_end(name) ⇒ Object



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

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
end

#tag_start(name, attrs) ⇒ Object



500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
# File 'lib/review/epubmaker.rb', line 500

def tag_start(name, attrs)
  if name =~ /\Ah(\d+)/
    if @level.present?
      raise "#{name}, #{attrs}"
    end
    @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



527
528
529
530
531
# File 'lib/review/epubmaker.rb', line 527

def text(text)
  if @level.present?
    @content << text.gsub("\t", " ") # FIXME:区切り文字
  end
end