Class: EBPS::Conversion::FachinfoXml::StreamListener
- Inherits:
-
Object
- Object
- EBPS::Conversion::FachinfoXml::StreamListener
- Includes:
- REXML::StreamListener
- Defined in:
- lib/ebps/conversion/fachinfo_xml.rb
Instance Attribute Summary collapse
-
#current_chapter ⇒ Object
readonly
Returns the value of attribute current_chapter.
-
#current_document ⇒ Object
readonly
Returns the value of attribute current_document.
-
#current_target ⇒ Object
readonly
Returns the value of attribute current_target.
-
#documents ⇒ Object
readonly
Returns the value of attribute documents.
Instance Method Summary collapse
- #end_fi ⇒ Object
- #end_i ⇒ Object
- #end_image ⇒ Object
- #end_monid ⇒ Object
-
#end_monographies ⇒ Object
nothing to be done.
- #end_owner ⇒ Object
-
#end_p ⇒ Object
(also: #end_paragraphSubtitle)
outermost tag, we can safely ignore this.
- #end_paragraph ⇒ Object
- #end_paragraphTitle ⇒ Object
- #end_table ⇒ Object
- #end_tb ⇒ Object
-
#end_td ⇒ Object
end of table body.
- #end_th ⇒ Object
-
#end_title ⇒ Object
end of table head.
- #end_tr ⇒ Object
-
#initialize ⇒ StreamListener
constructor
A new instance of StreamListener.
- #start_fi(attrs) ⇒ Object
- #start_i(attrs) ⇒ Object
- #start_image(attrs) ⇒ Object
- #start_monid(attrs) ⇒ Object
- #start_monographies(attrs) ⇒ Object
-
#start_owner(attrs) ⇒ Object
outermost tag, we can safely ignore this.
- #start_p(attrs) ⇒ Object
- #start_paragraph(attrs) ⇒ Object
- #start_paragraphSubtitle(attrs) ⇒ Object
- #start_paragraphTitle(attrs) ⇒ Object
- #start_table(attrs) ⇒ Object
- #start_tb(attrs) ⇒ Object
-
#start_td(attrs) ⇒ Object
start of table body.
- #start_th(attrs) ⇒ Object
-
#start_title(attrs) ⇒ Object
start of table head.
- #start_tr(attrs) ⇒ Object
-
#tag_end(name) ⇒ Object
ignore.
- #tag_start(name, attrs) ⇒ Object
- #text(data) ⇒ Object
Constructor Details
#initialize ⇒ StreamListener
Returns a new instance of StreamListener.
19 20 21 22 |
# File 'lib/ebps/conversion/fachinfo_xml.rb', line 19 def initialize @documents = [] @stack = [] end |
Instance Attribute Details
#current_chapter ⇒ Object (readonly)
Returns the value of attribute current_chapter.
17 18 19 |
# File 'lib/ebps/conversion/fachinfo_xml.rb', line 17 def current_chapter @current_chapter end |
#current_document ⇒ Object (readonly)
Returns the value of attribute current_document.
17 18 19 |
# File 'lib/ebps/conversion/fachinfo_xml.rb', line 17 def current_document @current_document end |
#current_target ⇒ Object (readonly)
Returns the value of attribute current_target.
17 18 19 |
# File 'lib/ebps/conversion/fachinfo_xml.rb', line 17 def current_target @current_target end |
#documents ⇒ Object (readonly)
Returns the value of attribute documents.
17 18 19 |
# File 'lib/ebps/conversion/fachinfo_xml.rb', line 17 def documents @documents end |
Instance Method Details
#end_fi ⇒ Object
23 24 25 |
# File 'lib/ebps/conversion/fachinfo_xml.rb', line 23 def end_fi @current_document = nil end |
#end_i ⇒ Object
65 66 67 68 69 70 |
# File 'lib/ebps/conversion/fachinfo_xml.rb', line 65 def end_i @stack.delete 'i' if @current_target.respond_to?(:set_format) @current_target.set_format *@stack end end |
#end_image ⇒ Object
71 72 73 |
# File 'lib/ebps/conversion/fachinfo_xml.rb', line 71 def end_image # nothing to be done end |
#end_monid ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ebps/conversion/fachinfo_xml.rb', line 26 def end_monid dir = File.join(EBPS.config.photos, @current_target.to_s) file_list = Dir.glob(File.join(dir, "*.jpg")).to_a.sort unless file_list.empty? @current_chapter.heading << (EBPS.config.language == 'de' ? 'Fotos' : 'Photos') @current_target = Text::Table.new file_list.each_with_index do |file, i| @current_target.next_row! if i > 0 # picture (right) picture = Text::Picture.new picture << File.read(file) #@current_target.rows.last << picture @current_target.rows[i][0] = picture # picture name (left) @current_target.next_cell! filename = File.basename(file).gsub(/\.jpg/,'').gsub(/^\d+_/,'') pic_number = if match = File.basename(file).match(/^(\d+)_/) match[1] end url = "https://pictures.e-mediat.net/WV_GetPictures/#{pic_number}_PIF_F.jpg" link = Text::LinkedParagraph.new(url, filename) #@current_target << filename @current_target.rows[i][1] = link end @current_chapter.add_paragraph(@current_target) end @current_target = nil @current_chapter = nil end |
#end_monographies ⇒ Object
nothing to be done
74 75 76 |
# File 'lib/ebps/conversion/fachinfo_xml.rb', line 74 def end_monographies # outermost tag, we can safely ignore this. end |
#end_owner ⇒ Object
88 89 90 91 |
# File 'lib/ebps/conversion/fachinfo_xml.rb', line 88 def end_owner end_paragraphTitle end_paragraph end |
#end_p ⇒ Object Also known as: end_paragraphSubtitle
outermost tag, we can safely ignore this.
77 78 79 80 |
# File 'lib/ebps/conversion/fachinfo_xml.rb', line 77 def end_p @current_chapter.add_paragraph(@current_target) if @current_target @current_target = nil end |
#end_paragraph ⇒ Object
81 82 83 |
# File 'lib/ebps/conversion/fachinfo_xml.rb', line 81 def end_paragraph @current_chapter = nil end |
#end_paragraphTitle ⇒ Object
85 86 87 |
# File 'lib/ebps/conversion/fachinfo_xml.rb', line 85 def end_paragraphTitle @current_target = nil end |
#end_table ⇒ Object
92 93 94 |
# File 'lib/ebps/conversion/fachinfo_xml.rb', line 92 def end_table end_p end |
#end_tb ⇒ Object
95 96 97 |
# File 'lib/ebps/conversion/fachinfo_xml.rb', line 95 def end_tb # end of table body. Ignored for now. end |
#end_td ⇒ Object
end of table body. Ignored for now.
98 99 100 |
# File 'lib/ebps/conversion/fachinfo_xml.rb', line 98 def end_td @in_td = false end |
#end_th ⇒ Object
101 102 103 |
# File 'lib/ebps/conversion/fachinfo_xml.rb', line 101 def end_th # end of table head. Ignored for now. end |
#end_title ⇒ Object
end of table head. Ignored for now.
104 105 106 |
# File 'lib/ebps/conversion/fachinfo_xml.rb', line 104 def end_title @current_target = nil end |
#end_tr ⇒ Object
107 108 109 |
# File 'lib/ebps/conversion/fachinfo_xml.rb', line 107 def end_tr @current_target << "\n" end |
#start_fi(attrs) ⇒ Object
110 111 112 113 |
# File 'lib/ebps/conversion/fachinfo_xml.rb', line 110 def start_fi attrs @documents.push(@current_document = Text::Document.new) @current_document end |
#start_i(attrs) ⇒ Object
114 115 116 117 118 119 |
# File 'lib/ebps/conversion/fachinfo_xml.rb', line 114 def start_i attrs @stack.push 'i' if @current_target.respond_to?(:set_format) @current_target.set_format *@stack.uniq end end |
#start_image(attrs) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/ebps/conversion/fachinfo_xml.rb', line 120 def start_image attrs config = EBPS.config raise <<-EOS unless config.image_prefix && config.image_suffix This monography contains images. Please configure both image_prefix and image_suffix EOS file = attrs["src"] + config.image_suffix src = File.join config.image_prefix, file handle = nil begin handle = open src picture = Text::Picture.new picture << handle.read @current_target = picture rescue @current_target = nil end ensure handle.close if handle end |
#start_monid(attrs) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/ebps/conversion/fachinfo_xml.rb', line 58 def start_monid attrs @current_chapter = Text::Chapter.new @current_document.add_chapter @current_chapter @current_target = Text::Paragraph.new #@current_chapter.heading << 'Fotos' @current_target end |
#start_monographies(attrs) ⇒ Object
140 141 142 |
# File 'lib/ebps/conversion/fachinfo_xml.rb', line 140 def start_monographies attrs # outermost tag, we can safely ignore this. end |
#start_owner(attrs) ⇒ Object
outermost tag, we can safely ignore this.
143 144 145 146 |
# File 'lib/ebps/conversion/fachinfo_xml.rb', line 143 def start_owner attrs start_paragraph attrs start_paragraphTitle attrs end |
#start_p(attrs) ⇒ Object
147 148 149 |
# File 'lib/ebps/conversion/fachinfo_xml.rb', line 147 def start_p attrs @current_target = Text::Paragraph.new end |
#start_paragraph(attrs) ⇒ Object
150 151 152 153 154 |
# File 'lib/ebps/conversion/fachinfo_xml.rb', line 150 def start_paragraph attrs @current_chapter = Text::Chapter.new @current_document.add_chapter @current_chapter @current_chapter end |
#start_paragraphSubtitle(attrs) ⇒ Object
155 156 157 |
# File 'lib/ebps/conversion/fachinfo_xml.rb', line 155 def start_paragraphSubtitle attrs @current_target = Text::Subheading.new end |
#start_paragraphTitle(attrs) ⇒ Object
158 159 160 |
# File 'lib/ebps/conversion/fachinfo_xml.rb', line 158 def start_paragraphTitle attrs @current_target = @current_chapter.heading end |
#start_table(attrs) ⇒ Object
161 162 163 164 165 |
# File 'lib/ebps/conversion/fachinfo_xml.rb', line 161 def start_table attrs paragraph = start_p attrs paragraph.set_format('pre') paragraph end |
#start_tb(attrs) ⇒ Object
166 167 168 |
# File 'lib/ebps/conversion/fachinfo_xml.rb', line 166 def start_tb attrs # start of table body. Ignored for now. end |
#start_td(attrs) ⇒ Object
start of table body. Ignored for now.
169 170 171 |
# File 'lib/ebps/conversion/fachinfo_xml.rb', line 169 def start_td attrs @in_td = true end |
#start_th(attrs) ⇒ Object
172 173 174 |
# File 'lib/ebps/conversion/fachinfo_xml.rb', line 172 def start_th attrs # start of table head. Ignored for now. end |
#start_title(attrs) ⇒ Object
start of table head. Ignored for now.
175 176 177 |
# File 'lib/ebps/conversion/fachinfo_xml.rb', line 175 def start_title attrs @current_target = @current_document.title end |
#start_tr(attrs) ⇒ Object
178 179 180 |
# File 'lib/ebps/conversion/fachinfo_xml.rb', line 178 def start_tr attrs # ignore. end_tr will add a newline character end |
#tag_end(name) ⇒ Object
ignore. end_tr will add a newline character
181 182 183 184 185 186 187 188 |
# File 'lib/ebps/conversion/fachinfo_xml.rb', line 181 def tag_end name method = "end_#{name}" if respond_to?(method) send method else raise "unhandled end tag '#{name}'" end end |
#tag_start(name, attrs) ⇒ Object
189 190 191 192 193 194 195 196 |
# File 'lib/ebps/conversion/fachinfo_xml.rb', line 189 def tag_start name, attrs method = "start_#{name}" if respond_to?(method) send method, attrs else raise "unhandled start tag '#{name}'" end end |
#text(data) ⇒ Object
197 198 199 200 201 202 |
# File 'lib/ebps/conversion/fachinfo_xml.rb', line 197 def text data if @current_target && data data = data.strip unless @in_td @current_target << data end end |