Class: Configuration::Thumbnail::ThumbnailSpec

Inherits:
Object
  • Object
show all
Includes:
ConditionalInclusion
Defined in:
lib/httpimagestore/configuration/thumbnailer.rb

Defined Under Namespace

Classes: Spec

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ConditionalInclusion

#excluded?, #included?, #inclusion_matcher

Constructor Details

#initialize(image_name, method, width, height, format, options = {}, matcher = nil) ⇒ ThumbnailSpec

Returns a new instance of ThumbnailSpec.



69
70
71
72
73
74
75
76
77
# File 'lib/httpimagestore/configuration/thumbnailer.rb', line 69

def initialize(image_name, method, width, height, format, options = {}, matcher = nil)
  @image_name = image_name
  @method = Spec.new(image_name, 'method', method)
  @width = Spec.new(image_name, 'width', width)
  @height = Spec.new(image_name, 'height', height)
  @format = Spec.new(image_name, 'format', format)
  @options = options.inject({}){|h, v| h[v.first] = Spec.new(image_name, v.first, v.last); h}
  inclusion_matcher matcher if matcher
end

Instance Attribute Details

#image_nameObject (readonly)

Returns the value of attribute image_name.



79
80
81
# File 'lib/httpimagestore/configuration/thumbnailer.rb', line 79

def image_name
  @image_name
end

Instance Method Details

#render(locals = {}) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/httpimagestore/configuration/thumbnailer.rb', line 81

def render(locals = {})
  options = @options.inject({}){|h, v| h[v.first] = v.last.render(locals); h}
  nested_options = options['options'] ? Hash[options.delete('options').to_s.split(',').map{|pair| pair.split(':', 2)}] : {}
  {
    @image_name =>
      [
        @method.render(locals),
        @width.render(locals),
        @height.render(locals),
        @format.render(locals),
        nested_options.merge(options)
      ]
  }
end