Class: ODFReport::Image
Constant Summary collapse
- IMAGE_DIR_NAME =
"Pictures"
Constants inherited from Field
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Returns the value of attribute files.
Class Method Summary collapse
- .include_image_file(zip_file, image_file) ⇒ Object
- .include_manifest_entry(content, image_file) ⇒ Object
Instance Method Summary collapse
-
#initialize(opts, &block) ⇒ Image
constructor
A new instance of Image.
- #replace!(doc, data_item = nil) ⇒ Object
Methods inherited from Field
Constructor Details
#initialize(opts, &block) ⇒ Image
Returns a new instance of Image.
8 9 10 11 |
# File 'lib/odf-report/image.rb', line 8 def initialize(opts, &block) @files = [] super end |
Instance Attribute Details
#files ⇒ Object (readonly)
Returns the value of attribute files.
6 7 8 |
# File 'lib/odf-report/image.rb', line 6 def files @files end |
Class Method Details
.include_image_file(zip_file, image_file) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/odf-report/image.rb', line 33 def self.include_image_file(zip_file, image_file) return unless image_file href = File.join(IMAGE_DIR_NAME, File.basename(image_file)) zip_file.update_file(href, File.read(image_file)) end |
.include_manifest_entry(content, image_file) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/odf-report/image.rb', line 41 def self.include_manifest_entry(content, image_file) return unless image_file return unless root_node = content.at("//manifest:manifest") href = File.join(IMAGE_DIR_NAME, File.basename(image_file)) entry = content.create_element('manifest:file-entry') entry['manifest:full-path'] = href entry['manifest:media-type'] = MIME::Types.type_for(href)[0].content_type root_node.add_child entry end |
Instance Method Details
#replace!(doc, data_item = nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/odf-report/image.rb', line 13 def replace!(doc, data_item = nil) frame = doc.xpath("//draw:frame[@draw:name='#{@name}']").first image = doc.xpath("//draw:frame[@draw:name='#{@name}']/draw:image").first return unless image file = @data_source.value if file image.attribute('href').content = File.join(IMAGE_DIR_NAME, File.basename(file)) frame.attribute('name').content = SecureRandom.uuid @files << file else frame.remove end end |