Class: Meatloaf::Ingredient

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

Overview

An Ingredient is simply one of the images to be compiled into the Sprite.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(image_css_url, x_offset = 0, y_offset = 0) ⇒ Ingredient

Returns a new instance of Ingredient.

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/meatloaf.rb', line 10

def initialize(image_css_url, x_offset = 0, y_offset = 0)
  @x_offset = x_offset
  @y_offset = y_offset

  # Find the asset associated with image_css_url.
  asset = Rails.application.assets.find_asset(image_css_url)
  raise ArgumentError.new("Can't find asset: #{image_css_url}") unless asset
  @image_path = asset.pathname.to_s
  
  # Get the dimensions of the image.
  @width, @height = `identify -format "%w %h" '#{@image_path}'`.chomp.split(' ').collect { |i| i.to_i }
end

Instance Attribute Details

#heightObject

Returns the value of attribute height.



8
9
10
# File 'lib/meatloaf.rb', line 8

def height
  @height
end

#image_pathObject

Returns the value of attribute image_path.



8
9
10
# File 'lib/meatloaf.rb', line 8

def image_path
  @image_path
end

#widthObject

Returns the value of attribute width.



8
9
10
# File 'lib/meatloaf.rb', line 8

def width
  @width
end

#x_offsetObject

Returns the value of attribute x_offset.



8
9
10
# File 'lib/meatloaf.rb', line 8

def x_offset
  @x_offset
end

#y_offsetObject

Returns the value of attribute y_offset.



8
9
10
# File 'lib/meatloaf.rb', line 8

def y_offset
  @y_offset
end