Class: Fleakr::Objects::Set

Inherits:
Object
  • Object
show all
Includes:
Support::Object
Defined in:
lib/fleakr/objects/set.rb

Overview

Set

Attributes

id

The ID for this photoset

title

The title of this photoset

description

The description of this set

count

Count of photos in this set

Associations

photos

The collection of photos for this set. See Fleakr::Objects::Photo

comments

All comments associated with this set. See Fleakr::Objects::Comment

Instance Method Summary collapse

Methods included from Support::Object

included

Instance Method Details

#file_prefix(index) ⇒ Object

:nodoc:



50
51
52
# File 'lib/fleakr/objects/set.rb', line 50

def file_prefix(index) # :nodoc:
  sprintf("%0#{self.count.length}d_", (index + 1))
end

#load_infoObject

:nodoc:



72
73
74
75
# File 'lib/fleakr/objects/set.rb', line 72

def load_info # :nodoc:
  response = Fleakr::Api::MethodRequest.with_response!('photosets.getInfo', :photoset_id => self.id)
  self.populate_from(response.body)
end

#primary_photoObject

Primary photo for this set. See Fleakr::Objects::Photo for more details.



56
57
58
# File 'lib/fleakr/objects/set.rb', line 56

def primary_photo
  @primary_photo ||= Photo.find_by_id(primary_photo_id)
end

#save_to(path, size) ⇒ Object

Save all photos in this set to the specified directory for the specified size. Allowed Sizes include :square, :small, :thumbnail, :medium,

:large, and :original. When saving the set, this method will create a subdirectory based on the set’s title.



40
41
42
43
44
45
46
47
48
# File 'lib/fleakr/objects/set.rb', line 40

def save_to(path, size)
  target = "#{path}/#{self.title}"
  FileUtils.mkdir(target) unless File.exist?(target)

  self.photos.each_with_index do |photo, index|
    image = photo.send(size)
    image.save_to(target, file_prefix(index)) unless image.nil?
  end
end

#urlObject

The URL for this set.



62
63
64
# File 'lib/fleakr/objects/set.rb', line 62

def url
  "http://www.flickr.com/photos/#{user_id}/sets/#{id}/"
end

#userObject

The user who created this set.



68
69
70
# File 'lib/fleakr/objects/set.rb', line 68

def user
  User.find_by_id(user_id)
end