Sha256: 7c143cd716b60896794b8545f5c9094128f1615337faa04dc9a38a2422ef56c4

Contents?: true

Size: 1011 Bytes

Versions: 14

Compression:

Stored size: 1011 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
    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.merge!(:ajust   => values.second.match(/\W/).to_s) unless values.second.match(/\W/).to_s.blank? 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 => options)
    end

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

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
attachment_magick-0.3.6 lib/attachment_magick/dsl.rb
attachment_magick-0.3.5 lib/attachment_magick/dsl.rb
attachment_magick-0.3.4 lib/attachment_magick/dsl.rb
attachment_magick-0.3.3 lib/attachment_magick/dsl.rb
attachment_magick-0.3.2 lib/attachment_magick/dsl.rb
attachment_magick-0.3.1 lib/attachment_magick/dsl.rb
attachment_magick-0.3 lib/attachment_magick/dsl.rb
attachment_magick-0.2.7 lib/attachment_magick/dsl.rb
attachment_magick-0.2.6 lib/attachment_magick/dsl.rb
attachment_magick-0.2.5 lib/attachment_magick/dsl.rb
attachment_magick-0.2.4 lib/attachment_magick/dsl.rb
attachment_magick-0.2.3 lib/attachment_magick/dsl.rb
attachment_magick-0.2.2 lib/attachment_magick/dsl.rb
attachment_magick-0.2.1 lib/attachment_magick/dsl.rb