Class: Compass::SassExtensions::Sprites::RowFitter
- Inherits:
-
Object
- Object
- Compass::SassExtensions::Sprites::RowFitter
- Extended by:
- Forwardable
- Defined in:
- lib/compass/sass_extensions/sprites/row_fitter.rb
Instance Attribute Summary collapse
-
#images ⇒ Object
readonly
Returns the value of attribute images.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
Instance Method Summary collapse
- #efficiency ⇒ Object
- #fit!(style = :scan) ⇒ Object
- #height ⇒ Object
-
#initialize(images) ⇒ RowFitter
constructor
A new instance of RowFitter.
- #width ⇒ Object
Constructor Details
#initialize(images) ⇒ RowFitter
Returns a new instance of RowFitter.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/compass/sass_extensions/sprites/row_fitter.rb', line 12 def initialize(images) @images = images.sort do |a,b| if a.height == b.height b.width <=> a.width else a.height <=> b.height end end @rows = [] end |
Instance Attribute Details
#images ⇒ Object (readonly)
Returns the value of attribute images.
9 10 11 |
# File 'lib/compass/sass_extensions/sprites/row_fitter.rb', line 9 def images @images end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
9 10 11 |
# File 'lib/compass/sass_extensions/sprites/row_fitter.rb', line 9 def rows @rows end |
Instance Method Details
#efficiency ⇒ Object
36 37 38 |
# File 'lib/compass/sass_extensions/sprites/row_fitter.rb', line 36 def efficiency @rows.inject(0) { |sum, row| sum += row.efficiency } ** @rows.length end |
#fit!(style = :scan) ⇒ Object
23 24 25 26 |
# File 'lib/compass/sass_extensions/sprites/row_fitter.rb', line 23 def fit!(style = :scan) send("#{style}_fit") @rows end |
#height ⇒ Object
32 33 34 |
# File 'lib/compass/sass_extensions/sprites/row_fitter.rb', line 32 def height @height ||= @rows.inject(0) {|sum, row| sum += row.height} end |
#width ⇒ Object
28 29 30 |
# File 'lib/compass/sass_extensions/sprites/row_fitter.rb', line 28 def width @width ||= @images.collect(&:width).max end |