Class: Compass::SassExtensions::Sprites::RowFitter

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/compass/sass_extensions/sprites/row_fitter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#imagesObject (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

#rowsObject (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

#efficiencyObject



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

#heightObject



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

#widthObject



28
29
30
# File 'lib/compass/sass_extensions/sprites/row_fitter.rb', line 28

def width
  @width ||= @images.collect(&:width).max
end