Class: FlickrMocks::Models::Photo

Inherits:
Object
  • Object
show all
Defined in:
lib/flickr_mocks/models/photo.rb

Instance Method Summary collapse

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_methodsObject

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

#largeObject

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

#mediumObject

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_640Object

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

#methodsObject

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_methodsObject



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?

#originalObject

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_idObject

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_urlObject

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_idObject

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

Returns:

  • (Boolean)


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

#smallObject

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

#squareObject

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

#thumbnailObject

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

Returns:

  • (Boolean)


66
67
68
# File 'lib/flickr_mocks/models/photo.rb', line 66

def usable?
  FlickrMocks::Api.default(:usable_licenses).include?(license.to_i)
end