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.



480
481
482
483
484
# File 'lib/review/epubmaker.rb', line 480

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

Instance Method Details

#tag_end(name) ⇒ Object



502
503
504
505
506
507
508
509
# File 'lib/review/epubmaker.rb', line 502

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

#tag_start(name, attrs) ⇒ Object



486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
# File 'lib/review/epubmaker.rb', line 486

def tag_start(name, attrs)
  if name =~ /\Ah(\d+)/
    unless @level.nil?
      raise "#{name}, #{attrs}"
    end
    @level = $1.to_i
    @id = attrs["id"] if !attrs["id"].nil?
  elsif !@level.nil?
    if name == "img" && !attrs["alt"].nil?
      @content << attrs["alt"]
    elsif name == "a" && !attrs["id"].nil?
      @id = attrs["id"]
    end
  end
end

#text(text) ⇒ Object



511
512
513
514
515
# File 'lib/review/epubmaker.rb', line 511

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