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

#folder_nameObject

:nodoc:



54
55
56
# File 'lib/fleakr/objects/set.rb', line 54

def folder_name # :nodoc:
  title.gsub("/", ' ').squeeze(' ')
end

#load_infoObject

:nodoc:



76
77
78
79
# File 'lib/fleakr/objects/set.rb', line 76

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.



60
61
62
# File 'lib/fleakr/objects/set.rb', line 60

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}/#{folder_name}"
  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.



66
67
68
# File 'lib/fleakr/objects/set.rb', line 66

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

#userObject

The user who created this set.



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

def user
  User.find_by_id(user_id)
end