Sha256: 4b5bc0cec8615d8a63a5e142181bd791a9f667124e3cb503adfad9f949834466

Contents?: true

Size: 947 Bytes

Versions: 2

Compression:

Stored size: 947 Bytes

Contents

module AttachmentMagick
  class DSL
    attr_reader :styles
    attr_reader :default_options

    def initialize(set, default_grids)
      @set    = set
      @styles = {}
      @default_grids = default_grids
      @default_options = {:crop => true}
    end

    def method_missing(name, *params, &blk)
      options = params.first

      if options.nil?
        options = @default_grids[name.to_sym]
      elsif options.is_a?(String)
        values = options.split('x')

        options = {}
        options.merge!(:width   => values.first.to_i) if values.first
        options.merge!(:height  => values.last.to_i)  if values.second

        options = @default_grids[name.to_sym].merge(options)
      elsif options.is_a?(Hash)
        options = @default_grids[name.to_sym].merge(options)
      end

      @styles.merge!(name.to_sym => @default_options.merge(options))
    end

    def styles
      @styles.empty? ? nil : @styles
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
attachment_magick-0.2.0 lib/attachment_magick/dsl.rb
attachment_magick-0.1.0 lib/attachment_magick/dsl.rb