Class: HTTPThumbnailerClient::URIBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/httpthumbnailer-client/uri_builder.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ URIBuilder

Returns a new instance of URIBuilder.



5
6
7
8
# File 'lib/httpthumbnailer-client/uri_builder.rb', line 5

def initialize(&block)
	@specs = []
	instance_eval(&block) if block
end

Instance Attribute Details

#specsObject (readonly)

Returns the value of attribute specs.



33
34
35
# File 'lib/httpthumbnailer-client/uri_builder.rb', line 33

def specs
  @specs
end

Class Method Details

.specs(*specs) ⇒ Object



18
19
20
21
22
# File 'lib/httpthumbnailer-client/uri_builder.rb', line 18

def self.specs(*specs)
	specs.each.with_object(new) do |spec, builder|
		builder.thumbnail_spec spec
	end.to_s
end

.thumbnail(method, width, height, format = 'jpeg', options = {}, &block) ⇒ Object



10
11
12
# File 'lib/httpthumbnailer-client/uri_builder.rb', line 10

def self.thumbnail(method, width, height, format = 'jpeg', options = {}, &block)
	self.new.thumbnail(method, width, height, format, options, &block).to_s
end

.thumbnails(&block) ⇒ Object



14
15
16
# File 'lib/httpthumbnailer-client/uri_builder.rb', line 14

def self.thumbnails(&block)
	self.new(&block).to_s
end

Instance Method Details

#thumbnail(method, width, height, format = 'jpeg', options = {}, &block) ⇒ Object



24
25
26
27
# File 'lib/httpthumbnailer-client/uri_builder.rb', line 24

def thumbnail(method, width, height, format = 'jpeg', options = {}, &block)
	thumbnail_spec ThumbnailSpec::Builder.new(method, width.to_s, height.to_s, format, options, &block).spec
	self
end

#thumbnail_spec(spec) ⇒ Object



29
30
31
# File 'lib/httpthumbnailer-client/uri_builder.rb', line 29

def thumbnail_spec(spec)
	@specs << spec
end

#to_sObject Also known as: get



35
36
37
38
# File 'lib/httpthumbnailer-client/uri_builder.rb', line 35

def to_s
	uri = @specs.length > 1 ? '/thumbnails' : '/thumbnail'
	"#{uri}/#{@specs.map(&:to_s).join('/')}"
end