Class: Clarus::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/clarus/image.rb

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ Image

Returns a new instance of Image.



7
8
9
10
11
# File 'lib/clarus/image.rb', line 7

def initialize(uri)
  @image_path = uri
  get_image_data
  get_image_dimensions
end

Instance Method Details

#encoded_imageObject



21
22
23
# File 'lib/clarus/image.rb', line 21

def encoded_image
  @image_blob ||= Base64.encode64(get_image_data)
end

#get_image_dataObject



17
18
19
# File 'lib/clarus/image.rb', line 17

def get_image_data
  @image_data ||= open(@image_path).read
end

#get_image_dimensionsObject



13
14
15
# File 'lib/clarus/image.rb', line 13

def get_image_dimensions
  @image_size = ImageSize.new(get_image_data)
end

#renderObject



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/clarus/image.rb', line 25

def render
  document_template = File.read(File.expand_path('../templates/image_template.erb', __FILE__))
  filename = File.basename(@image_path)
  wordml_filename = "wordml://#{Time.now.to_i}#{filename}"
  Erubis::Eruby.new(document_template).result(
    :wordml_filename => wordml_filename,
    :width => @image_size.width,
    :height => @image_size.height,
    :filename => filename,
    :bindata => encoded_image
  )
end