Class: ReVIEW::EPUBMaker::ReVIEWHeaderListener
- Includes:
- REXML::StreamListener
- Defined in:
- lib/review/epubmaker.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.
442 443 444 445 446 |
# File 'lib/review/epubmaker.rb', line 442 def initialize(headlines) @level = nil @content = "" @headlines = headlines end |
Instance Method Details
#tag_end(name) ⇒ Object
464 465 466 467 468 469 470 471 |
# File 'lib/review/epubmaker.rb', line 464 def tag_end(name) if name =~ /\Ah\d+/ @headlines.push({"level" => @level, "id" => @id, "title" => @content}) if @id.present? @content = "" @level = nil @id = nil end end |
#tag_start(name, attrs) ⇒ Object
448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 |
# File 'lib/review/epubmaker.rb', line 448 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? 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
473 474 475 476 477 |
# File 'lib/review/epubmaker.rb', line 473 def text(text) if @level.present? @content << text.gsub("\t", " ") # FIXME:区切り文字 end end |