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)
-
- (Object) images
readonly
Returns the value of attribute images.
-
- (Object) max_width
readonly
Returns the value of attribute max_width.
Instance Method Summary (collapse)
- - (Object) add(image) (also: #<<)
- - (Object) efficiency
- - (Object) height
-
- (ImageRow) initialize(max_width)
constructor
A new instance of ImageRow.
- - (Object) total_width
- - (Object) width
- - (Boolean) will_fit?(image)
Constructor Details
- (ImageRow) initialize(max_width)
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
- (Object) images (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 |
- (Object) max_width (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
- (Object) add(image) 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 |
- (Object) efficiency
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 |
- (Object) height
25 26 27 |
# File 'lib/compass/sass_extensions/sprites/image_row.rb', line 25 def height images.map(&:height).max end |
- (Object) total_width
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 |
- (Object) width
29 30 31 |
# File 'lib/compass/sass_extensions/sprites/image_row.rb', line 29 def width images.map(&:width).max end |
- (Boolean) will_fit?(image)
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 |