Class: FlickrMocks::Models::Photo
- Inherits:
-
Object
- Object
- FlickrMocks::Models::Photo
- Defined in:
- lib/flickr_mocks/models/photo.rb
Instance Method Summary collapse
-
#==(other) ⇒ Object
compares two objects by value rather than object_id.
-
#delegated_instance_methods ⇒ Object
returns the list of methods that are delegated by object.
-
#initialize(photo) ⇒ Photo
constructor
A new instance of Photo.
-
#initialize_copy(orig) ⇒ Object
compares value for internal state rather than object_id.
-
#large ⇒ Object
returns url for large sized photo.
-
#medium ⇒ Object
returns url for medium sized photo.
-
#medium_640 ⇒ Object
returns url for medium 640 sized photo.
-
#method_missing(id, *args, &block) ⇒ Object
delegates methods that are returned by delegated instance method as well as method :‘method 640’.
-
#methods ⇒ Object
returns delegated methods as well as regular methods.
- #old_methods ⇒ Object
- #old_respond_to? ⇒ Object
-
#original ⇒ Object
returns url for original sized photo.
-
#owner_id ⇒ Object
returns Flickr id for owner of photo.
-
#owner_url ⇒ Object
return url for copyright owner of photo.
-
#photo_id ⇒ Object
returns Flickr id for photo.
-
#respond_to?(method, type = false) ⇒ Boolean
returns true for delegated and regular methods.
-
#small ⇒ Object
returns url for small sized photo.
-
#square ⇒ Object
Return url for square sized photo.
-
#thumbnail ⇒ Object
returns url for thumbnail sized photo.
-
#usable? ⇒ Boolean
returns true if photo license can be used for commercial purposes.
Constructor Details
#initialize(photo) ⇒ Photo
Returns a new instance of Photo.
4 5 6 7 8 |
# File 'lib/flickr_mocks/models/photo.rb', line 4 def initialize(photo) self.delegated_to_object = photo @delegated_instance_methods = @delegated_to_object.methods(false).push(:flickr_type) @extended_photo = photo.methods.include?(:originalsecret) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(id, *args, &block) ⇒ Object
delegates methods that are returned by delegated instance method as well as method :‘method 640’
88 89 90 91 92 |
# File 'lib/flickr_mocks/models/photo.rb', line 88 def method_missing(id,*args,&block) return @delegated_to_object.send(id,*args,&block) if delegated_instance_methods.include?(id) return medium_640 if id.to_sym == :'medium 640' super end |
Instance Method Details
#==(other) ⇒ Object
compares two objects by value rather than object_id
71 72 73 |
# File 'lib/flickr_mocks/models/photo.rb', line 71 def ==(other) @delegated_to_object == other.instance_eval('@delegated_to_object') end |
#delegated_instance_methods ⇒ Object
returns the list of methods that are delegated by object
82 83 84 |
# File 'lib/flickr_mocks/models/photo.rb', line 82 def delegated_instance_methods @delegated_instance_methods end |
#initialize_copy(orig) ⇒ Object
compares value for internal state rather than object_id
76 77 78 79 |
# File 'lib/flickr_mocks/models/photo.rb', line 76 def initialize_copy(orig) super @delegated_to_object = @delegated_to_object.clone end |
#large ⇒ Object
returns url for large sized photo
36 37 38 |
# File 'lib/flickr_mocks/models/photo.rb', line 36 def large FlickRaw.url_b self end |
#medium ⇒ Object
returns url for medium sized photo
31 32 33 |
# File 'lib/flickr_mocks/models/photo.rb', line 31 def medium FlickRaw.url self end |
#medium_640 ⇒ Object
returns url for medium 640 sized photo
41 42 43 |
# File 'lib/flickr_mocks/models/photo.rb', line 41 def medium_640 FlickRaw.url_z self end |
#methods ⇒ Object
returns delegated methods as well as regular methods
104 105 106 |
# File 'lib/flickr_mocks/models/photo.rb', line 104 def methods delegated_instance_methods + old_methods end |
#old_methods ⇒ Object
102 |
# File 'lib/flickr_mocks/models/photo.rb', line 102 alias :old_methods :methods |
#old_respond_to? ⇒ Object
94 |
# File 'lib/flickr_mocks/models/photo.rb', line 94 alias :old_respond_to? :respond_to? |
#original ⇒ Object
returns url for original sized photo
16 17 18 |
# File 'lib/flickr_mocks/models/photo.rb', line 16 def original respond_to?(:originalsecret) ? FlickRaw.url_o(self) : nil end |
#owner_id ⇒ Object
returns Flickr id for owner of photo
51 52 53 54 55 56 57 58 |
# File 'lib/flickr_mocks/models/photo.rb', line 51 def owner_id case owner when String then owner else return owner.nsid if owner.respond_to?(:nsid) return owner.to_s end end |
#owner_url ⇒ Object
return url for copyright owner of photo
46 47 48 |
# File 'lib/flickr_mocks/models/photo.rb', line 46 def owner_url FlickRaw.url_photopage self end |
#photo_id ⇒ Object
returns Flickr id for photo
61 62 63 |
# File 'lib/flickr_mocks/models/photo.rb', line 61 def photo_id id end |
#respond_to?(method, type = false) ⇒ Boolean
returns true for delegated and regular methods
96 97 98 99 100 |
# File 'lib/flickr_mocks/models/photo.rb', line 96 def respond_to?(method,type=false) return true if method.to_sym == :'medium 640' return true if delegated_instance_methods.include?(method) old_respond_to?(method,type) end |
#small ⇒ Object
returns url for small sized photo
26 27 28 |
# File 'lib/flickr_mocks/models/photo.rb', line 26 def small FlickRaw.url_m self end |
#square ⇒ Object
Return url for square sized photo
11 12 13 |
# File 'lib/flickr_mocks/models/photo.rb', line 11 def square FlickRaw.url_s self end |
#thumbnail ⇒ Object
returns url for thumbnail sized photo
21 22 23 |
# File 'lib/flickr_mocks/models/photo.rb', line 21 def thumbnail FlickRaw.url_t self end |
#usable? ⇒ Boolean
returns true if photo license can be used for commercial purposes
66 67 68 |
# File 'lib/flickr_mocks/models/photo.rb', line 66 def usable? FlickrMocks::Api.default(:usable_licenses).include?(license.to_i) end |