Class: Consolidate::Image

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, width:, height:, path: nil, url: nil, contents: nil, dpix: nil, dpiy: nil) ⇒ Image

Returns a new instance of Image.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/consolidate/image.rb', line 6

def initialize name:, width:, height:, path: nil, url: nil, contents: nil, dpix: nil, dpiy: nil
  @name = name
  @width = width
  @height = height
  @path = path
  @url = url
  @contents = contents
  @aspect_ratio = width.to_f / height.to_f
  #  TODO: Read this from the contents
  @dpi = {x: dpix || 72, y: dpiy || 72}
end

Instance Attribute Details

#aspect_ratioObject (readonly)

Returns the value of attribute aspect_ratio.



5
6
7
# File 'lib/consolidate/image.rb', line 5

def aspect_ratio
  @aspect_ratio
end

#dpiObject (readonly)

Returns the value of attribute dpi.



5
6
7
# File 'lib/consolidate/image.rb', line 5

def dpi
  @dpi
end

#heightObject (readonly)

Returns the value of attribute height.



5
6
7
# File 'lib/consolidate/image.rb', line 5

def height
  @height
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/consolidate/image.rb', line 5

def name
  @name
end

#widthObject (readonly)

Returns the value of attribute width.



5
6
7
# File 'lib/consolidate/image.rb', line 5

def width
  @width
end

Instance Method Details

#contentsObject



20
# File 'lib/consolidate/image.rb', line 20

def contents = @contents ||= contents_from_path || contents_from_url

#to_sObject



18
# File 'lib/consolidate/image.rb', line 18

def to_s = name