Class: ThumbnailSpec

Inherits:
Object
  • Object
show all
Defined in:
lib/httpthumbnailer/thumbnail_specs.rb

Defined Under Namespace

Classes: BadThubnailSpecError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of ThumbnailSpec.



46
47
48
49
50
51
52
# File 'lib/httpthumbnailer/thumbnail_specs.rb', line 46

def initialize(method, width, height, format, options = {})
	@method = method
	@width = cast_dimension(width)
	@height = cast_dimension(height)
	@format = (format == 'input' ? :input : format.upcase)
	@options = options
end

Instance Attribute Details

#formatObject (readonly)

Returns the value of attribute format.



69
70
71
# File 'lib/httpthumbnailer/thumbnail_specs.rb', line 69

def format
  @format
end

#heightObject (readonly)

Returns the value of attribute height.



69
70
71
# File 'lib/httpthumbnailer/thumbnail_specs.rb', line 69

def height
  @height
end

#methodObject (readonly)

Returns the value of attribute method.



69
70
71
# File 'lib/httpthumbnailer/thumbnail_specs.rb', line 69

def method
  @method
end

#optionsObject (readonly)

Returns the value of attribute options.



69
70
71
# File 'lib/httpthumbnailer/thumbnail_specs.rb', line 69

def options
  @options
end

#widthObject (readonly)

Returns the value of attribute width.



69
70
71
# File 'lib/httpthumbnailer/thumbnail_specs.rb', line 69

def width
  @width
end

Class Method Details

.from_uri(spec) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/httpthumbnailer/thumbnail_specs.rb', line 54

def self.from_uri(spec)
	method, width, height, format, *options = *spec.split(',')
	raise BadThubnailSpecError::MissingArgumentError.new(spec) unless method and width and height and format

	opts = {}
	options.each do |option|
		key, value = option.split(':')
		raise BadThubnailSpecError::MissingOptionKeyOrValueError.new(option) unless key and value
		opts[key] = value
	end

	ThumbnailSpec.new(method, width, height, format, opts)
end

Instance Method Details

#to_sObject



71
72
73
# File 'lib/httpthumbnailer/thumbnail_specs.rb', line 71

def to_s
	"#{method} #{width}x#{height} (#{format.downcase}) #{options.inspect}"
end