Class: ODDB::ChapterParse::Writer
- Defined in:
- ext/chapterparse/src/writer.rb
Instance Method Summary collapse
- #chapter ⇒ Object
-
#initialize ⇒ Writer
constructor
A new instance of Writer.
- #new_font(font) ⇒ Object
- #new_fonthandler(fh) ⇒ Object
- #new_tablehandler(th) ⇒ Object
- #preformatted?(target) ⇒ Boolean
- #send_flowing_data(data) ⇒ Object
- #send_line_break ⇒ Object
- #send_literal_data(data) ⇒ Object
Constructor Details
Instance Method Details
#chapter ⇒ Object
15 16 17 18 |
# File 'ext/chapterparse/src/writer.rb', line 15 def chapter @chapter.clean! @chapter end |
#new_font(font) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'ext/chapterparse/src/writer.rb', line 19 def new_font(font) return if @table case font when [nil, 1, nil, nil] if(@target.is_a?(Text::Paragraph) \ && !(@target.empty? || @target.preformatted?)) @target.set_format(:italic) else @section = @chapter.next_section @subheading = @target = @section.subheading end when [nil, nil, nil, 1] unless(preformatted?(@target)) @target = @section.next_paragraph @target.preformatted! end else if(@target.is_a?(Text::Paragraph)) unless(@target.preformatted?) @target.set_format() end else @target = @section.next_paragraph end end end |
#new_fonthandler(fh) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'ext/chapterparse/src/writer.rb', line 45 def new_fonthandler(fh) if(@target.is_a?(Text::Paragraph)) if(fh && fh.attribute('face') == 'Symbol') @target.augment_format(:symbol) else @target.reduce_format(:symbol) end if(fh && (align = fh.attribute('vertical-align'))) @target.augment_format(align.to_sym) else @target.reduce_format(:superscript) @target.reduce_format(:subscript) end end end |
#new_tablehandler(th) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'ext/chapterparse/src/writer.rb', line 60 def new_tablehandler(th) if(@table) paragraph = @section.next_paragraph paragraph.preformatted! paragraph << @table.to_s end @table = @target = th if(th.nil?) @target = @section.next_paragraph end end |
#preformatted?(target) ⇒ Boolean
71 72 73 74 |
# File 'ext/chapterparse/src/writer.rb', line 71 def preformatted?(target) target.is_a?(Text::Paragraph) \ && target.preformatted? end |
#send_flowing_data(data) ⇒ Object
89 90 91 92 93 94 |
# File 'ext/chapterparse/src/writer.rb', line 89 def send_flowing_data(data) if(preformatted?(@target)) @target = @section.next_paragraph end @target << data.gsub(/\302\240/u, " ") end |
#send_line_break ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'ext/chapterparse/src/writer.rb', line 75 def send_line_break if(!@table && (@target.empty? && @subheading) \ || @target == @section.subheading) @subheading << "\n" @subheading = nil end if(@table) @table.next_line elsif(preformatted?(@target)) @target << "\n" else @target = @section.next_paragraph end end |
#send_literal_data(data) ⇒ Object
95 96 97 |
# File 'ext/chapterparse/src/writer.rb', line 95 def send_literal_data(data) @target << data.gsub(/\302\240/u, " ").gsub(/\r\n?/u, "\n") end |