Class: Creek::Drawing
Constant Summary collapse
- COLUMNS =
('A'..'AZ').to_a
Instance Method Summary collapse
-
#has_images? ⇒ Boolean
Returns false if there are no images in the drawing file or the drawing file does not exist, true otherwise.
-
#images_at(cell_name) ⇒ Object
Extracts images from excel to tmpdir for a cell, if the images are not already extracted (multiple calls or same image file in multiple cells).
-
#initialize(book, drawing_filepath) ⇒ Drawing
constructor
A new instance of Drawing.
Methods included from Utils
#expand_to_rels_path, #file_exist?, #parse_xml
Constructor Details
#initialize(book, drawing_filepath) ⇒ Drawing
Returns a new instance of Drawing.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/creek/drawing.rb', line 11 def initialize(book, drawing_filepath) @book = book @drawing_filepath = drawing_filepath @drawings = [] @drawings_rels = [] @images_pathnames = Hash.new { |hash, key| hash[key] = [] } if file_exist?(@drawing_filepath) load_drawings_and_rels load_images_pathnames_by_cells if has_images? end end |
Instance Method Details
#has_images? ⇒ Boolean
Returns false if there are no images in the drawing file or the drawing file does not exist, true otherwise.
26 27 28 |
# File 'lib/creek/drawing.rb', line 26 def has_images? @has_images ||= !@drawings.empty? end |
#images_at(cell_name) ⇒ Object
Extracts images from excel to tmpdir for a cell, if the images are not already extracted (multiple calls or same image file in multiple cells). Returns array of images as Pathname objects or nil.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/creek/drawing.rb', line 33 def images_at(cell_name) coordinate = calc_coordinate(cell_name) pathnames_at_coordinate = @images_pathnames[coordinate] return if pathnames_at_coordinate.empty? pathnames_at_coordinate.map do |image_pathname| if image_pathname.exist? image_pathname else excel_image_path = "xl/media#{image_pathname.to_path.split(tmpdir).last}" IO.copy_stream(@book.files.file.open(excel_image_path), image_pathname.to_path) image_pathname end end end |