Sha256: 0244da61f87896f7cf61f79dbc35b3403808ea7294578594293383f1c814df46

Contents?: true

Size: 1.01 KB

Versions: 16

Compression:

Stored size: 1.01 KB

Contents

module Qbrick
  class ImageSize
    attr_accessor :name, :width, :height

    def label
      I18n.t("activerecord.attributes.qbrick/image_size.sizes.#{name}")
    end

    class << self
      def all
        @all ||= []
      end

      def build_defaults!
        @all = [gallery_size, teaser_size]
      end

      def find_by_name(name)
        all.find { |size| size.name.to_s == name.to_s }
      end

      def clear!
        @all = []
      end

      def add(name, width, height)
        all << ImageSize.new.tap do |size|
          size.name = name.to_sym
          size.width = width
          size.height = height
        end
      end

      def gallery_size
        @gallery_size ||= ImageSize.new.tap do |size|
          size.name = :gallery
          size.width = 960
          size.height = 540
        end
      end

      def teaser_size
        @teaser_size ||= ImageSize.new.tap do |size|
          size.name = :teaser
          size.width = 320
          size.height = 180
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
qbrick-2.7.1 app/models/qbrick/image_size.rb
qbrick-2.7 app/models/qbrick/image_size.rb
qbrick-2.6.10 app/models/qbrick/image_size.rb
qbrick-2.6.9 app/models/qbrick/image_size.rb
qbrick-2.6.8 app/models/qbrick/image_size.rb
qbrick-2.6.7 app/models/qbrick/image_size.rb
qbrick-2.6.6 app/models/qbrick/image_size.rb
qbrick-2.6.5 app/models/qbrick/image_size.rb
qbrick-2.6.4 app/models/qbrick/image_size.rb
qbrick-2.6.3 app/models/qbrick/image_size.rb
qbrick-2.6.2 app/models/qbrick/image_size.rb
qbrick-2.6.1 app/models/qbrick/image_size.rb
qbrick-2.6.0 app/models/qbrick/image_size.rb
qbrick-2.5.2 app/models/qbrick/image_size.rb
qbrick-2.5.1 app/models/qbrick/image_size.rb
qbrick-2.5.0 app/models/qbrick/image_size.rb