Class: Compass::SassExtensions::Sprites::ImageRow
- Inherits:
-
Object
- Object
- Compass::SassExtensions::Sprites::ImageRow
- Extended by:
- Forwardable
- Defined in:
- lib/compass/sass_extensions/sprites/image_row.rb
Instance Attribute Summary collapse
-
#images ⇒ Object
readonly
Returns the value of attribute images.
-
#max_width ⇒ Object
readonly
Returns the value of attribute max_width.
Instance Method Summary collapse
- #add(image) ⇒ Object (also: #<<)
- #efficiency ⇒ Object
- #height ⇒ Object
-
#initialize(max_width) ⇒ ImageRow
constructor
A new instance of ImageRow.
- #total_width ⇒ Object
- #width ⇒ Object
- #will_fit?(image) ⇒ Boolean
Constructor Details
#initialize(max_width) ⇒ ImageRow
Returns a new instance of ImageRow.
12 13 14 15 |
# File 'lib/compass/sass_extensions/sprites/image_row.rb', line 12 def initialize(max_width) @images = [] @max_width = max_width end |
Instance Attribute Details
#images ⇒ Object (readonly)
Returns the value of attribute images.
9 10 11 |
# File 'lib/compass/sass_extensions/sprites/image_row.rb', line 9 def images @images end |
#max_width ⇒ Object (readonly)
Returns the value of attribute max_width.
9 10 11 |
# File 'lib/compass/sass_extensions/sprites/image_row.rb', line 9 def max_width @max_width end |
Instance Method Details
#add(image) ⇒ Object Also known as: <<
17 18 19 20 21 |
# File 'lib/compass/sass_extensions/sprites/image_row.rb', line 17 def add(image) return false if !will_fit?(image) @images << image true end |
#efficiency ⇒ Object
37 38 39 |
# File 'lib/compass/sass_extensions/sprites/image_row.rb', line 37 def efficiency 1 - (total_width.to_f / max_width.to_f) end |
#height ⇒ Object
25 26 27 |
# File 'lib/compass/sass_extensions/sprites/image_row.rb', line 25 def height images.map(&:height).max end |
#total_width ⇒ Object
33 34 35 |
# File 'lib/compass/sass_extensions/sprites/image_row.rb', line 33 def total_width images.inject(0) {|sum, img| sum + img.width } end |
#width ⇒ Object
29 30 31 |
# File 'lib/compass/sass_extensions/sprites/image_row.rb', line 29 def width images.map(&:width).max end |
#will_fit?(image) ⇒ Boolean
41 42 43 |
# File 'lib/compass/sass_extensions/sprites/image_row.rb', line 41 def will_fit?(image) (total_width + image.width) <= max_width end |