Class: Kiva::Image

Inherits:
Object
  • Object
show all
Includes:
DynamicInitializer
Defined in:
lib/ruby-kiva/image.rb

Constant Summary collapse

SIZES =
%w(w80h80 w200h200 w325h250 w450h360 fullsize)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DynamicInitializer

included

Instance Attribute Details

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/ruby-kiva/image.rb', line 4

def id
  @id
end

#template_idObject

Returns the value of attribute template_id.



4
5
6
# File 'lib/ruby-kiva/image.rb', line 4

def template_id
  @template_id
end

Instance Method Details

#to_sObject



8
9
10
# File 'lib/ruby-kiva/image.rb', line 8

def to_s
  "<Image #{self.template_id} / #{self.id}>"
end

#url(size = 'w80h80') ⇒ Object

Build the URL for this Image. See SIZES for valid sizes, defaults to w80h80



14
15
16
17
18
# File 'lib/ruby-kiva/image.rb', line 14

def url(size = 'w80h80')
  raise 'Must have a template id and an id' unless self.template_id && self.id
  raise "Unknown size #{size}" unless SIZES.include?(size.to_s)
  "http://www.kiva.org/img/#{size}/#{self.id}.jpg"
end