Class: Flickry::Photo
- Inherits:
-
Base
- Object
- OpenStruct
- SuperStruct
- Base
- Flickry::Photo
- Defined in:
- lib/flickry/photo.rb
Instance Method Summary collapse
-
#comments ⇒ Object
Lazily fetches the photo’s comments when called, memoizes so later calls are faster…
-
#favorite? ⇒ Boolean
W Booleans.
-
#initialize(flickr_id) ⇒ Photo
constructor
A new instance of Photo.
-
#last_updated_at ⇒ Object
Time/Dates.
- #posted_at ⇒ Object
-
#sizes ⇒ Object
Lazily fetches the photo’s sizes when called, memoizes so later calls are faster…
-
#tag_list(separator = ', ') ⇒ Object
Join tags into a single string.
- #taken_at ⇒ Object
- #uploaded_at ⇒ Object
- #visible_to_family? ⇒ Boolean
- #visible_to_friends? ⇒ Boolean
- #visible_to_public? ⇒ Boolean
Methods inherited from Base
Methods inherited from SuperStruct
#[], #[]=, #each, #each_pair, #members
Constructor Details
#initialize(flickr_id) ⇒ Photo
Returns a new instance of Photo.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/flickry/photo.rb', line 3 def initialize(flickr_id) super(nil) foto = flickr.photos.getInfo(:photo_id => flickr_id) self.raw_photo = foto self.photo_id = flickr_id extract_attrs!(foto, [:dateuploaded, :description, :farm, :id, :isfavorite, :media, :notes, :originalformat, :originalsecret, :rotation, :secret, :server, :tags, :title]) extract_attrs_into_substructs!(foto, { :dates => [:lastupdate, :posted, :taken, :takengranularity], :editability => [:canaddmeta, :cancomment], :geoperms => [:iscontact, :isfamily, :isfriend, :ispublic], :usage => [:canblog, :candownload, :canprint], :visibility => [:isfamily, :isfriend, :ispublic] }) self.location = Flickry::Location.new(foto.respond_to?(:location) ? foto.location : nil) self.owner = Flickry::Person.find(foto.respond_to?(:owner) ? foto.owner.nsid : nil) self.license = Flickry::License.new(foto.respond_to?(:license) ? foto.license : 99) = self..dup self. = .collect do |t| Flickry::Tag.new(t) end self.urls = foto.urls.collect { |u| u.to_s } end |
Instance Method Details
#comments ⇒ Object
Lazily fetches the photo’s comments when called, memoizes so later calls are faster…
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/flickry/photo.rb', line 39 def comments return @comments if @comments if raw_photo.comments.to_i == 0 @comments = [] else @comments = [] flickr_comments = flickr.photos.comments.getList(:photo_id => self.photo_id) flickr_comments.each do |comment| @comments << Flickry::Comment.new(comment) end end return @comments end |
#favorite? ⇒ Boolean
W Booleans
82 83 84 |
# File 'lib/flickry/photo.rb', line 82 def favorite? self.isfavorite == 1 end |
#last_updated_at ⇒ Object
Time/Dates
55 56 57 |
# File 'lib/flickry/photo.rb', line 55 def last_updated_at dates_to_time(:lastupdate) end |
#posted_at ⇒ Object
59 60 61 |
# File 'lib/flickry/photo.rb', line 59 def posted_at dates_to_time(:posted) end |
#sizes ⇒ Object
Lazily fetches the photo’s sizes when called, memoizes so later calls are faster…
32 33 34 |
# File 'lib/flickry/photo.rb', line 32 def sizes @sizes ||= Flickry::Sizes.new(flickr.photos.getSizes(:photo_id => self.photo_id)) end |
#tag_list(separator = ', ') ⇒ Object
Join tags into a single string
76 77 78 |
# File 'lib/flickry/photo.rb', line 76 def tag_list(separator = ', ') self..join(separator) end |
#taken_at ⇒ Object
63 64 65 |
# File 'lib/flickry/photo.rb', line 63 def taken_at Time.parse(self.dates.taken) end |
#uploaded_at ⇒ Object
67 68 69 70 71 |
# File 'lib/flickry/photo.rb', line 67 def uploaded_at uploaded = self.dateuploaded.to_i return nil if uploaded == 0 Time.at(uploaded) end |
#visible_to_family? ⇒ Boolean
86 87 88 |
# File 'lib/flickry/photo.rb', line 86 def visible_to_family? self.visibility.isfamily == 1 end |
#visible_to_friends? ⇒ Boolean
90 91 92 |
# File 'lib/flickry/photo.rb', line 90 def visible_to_friends? self.visibility.isfriend == 1 end |
#visible_to_public? ⇒ Boolean
94 95 96 |
# File 'lib/flickry/photo.rb', line 94 def visible_to_public? self.visibility.ispublic == 1 end |