Sha256: a820a008af7a71b76743c4639e8caafe294bf001fbf62980e8c645ec0033110a

Contents?: true

Size: 1003 Bytes

Versions: 2

Compression:

Stored size: 1003 Bytes

Contents

require 'forwardable'

module Compass
  module SassExtensions
    module Sprites
      class ImageRow
        extend Forwardable

        attr_reader :images, :max_width
        def_delegators :@images, :last, :delete, :empty?, :length
        
        def initialize(max_width)
          @images = []
          @max_width = max_width
        end
        
        def add(image)
          return false if !will_fit?(image)
          @images << image
          true
        end

        alias :<< :add
        
        def height
          images.map(&:height).max
        end
        
        def width
          images.map(&:width).max
        end

        def total_width
          images.inject(0) {|sum, img| sum + img.width }
        end
        
        def efficiency
          1 - (total_width.to_f / max_width.to_f)
        end

        def will_fit?(image)
          (total_width + image.width) <= max_width
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
compass-sourcemaps-0.12.3.sourcemaps.a4836f1 lib/compass/sass_extensions/sprites/image_row.rb
compass-sourcemaps-0.12.2.sourcemaps.57a186c lib/compass/sass_extensions/sprites/image_row.rb