Class: FlickrMocks::Models::PhotoSize
- Inherits:
-
Object
- Object
- FlickrMocks::Models::PhotoSize
- Defined in:
- lib/flickr_mocks/models/photo_size.rb
Instance Method Summary collapse
-
#==(other) ⇒ Object
compares the complete internal state of two PhotoDetails objects rather than simply comparing object_id’s.
-
#delegated_instance_methods ⇒ Object
returns list of methods that are delegated to other objects.
-
#id ⇒ Object
returns the flickr id for the given photo.
-
#initialize(object) ⇒ PhotoSize
constructor
A new instance of PhotoSize.
-
#initialize_copy(orig) ⇒ Object
compares value for internal state rather than object_id.
-
#method_missing(id, *args, &block) ⇒ Object
delegates array methods to the @dimensions object.
-
#methods ⇒ Object
returns delegated methods as well as regular methods.
- #old_methods ⇒ Object
- #old_respond_to? ⇒ Object
-
#respond_to?(method, type = false) ⇒ Boolean
returns true for delegated and regular methods.
-
#secret ⇒ Object
returns the flickr secret for the given photo.
-
#size ⇒ Object
returns the string that contains the photo’s size.
Constructor Details
#initialize(object) ⇒ PhotoSize
Returns a new instance of PhotoSize.
4 5 6 |
# File 'lib/flickr_mocks/models/photo_size.rb', line 4 def initialize(object) self.delegated_to_object= object end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(id, *args, &block) ⇒ Object
delegates array methods to the @dimensions object
38 39 40 41 |
# File 'lib/flickr_mocks/models/photo_size.rb', line 38 def method_missing(id,*args,&block) return @delegated_to_object.send(id,*args,&block) if delegated_instance_methods.include?(id) super end |
Instance Method Details
#==(other) ⇒ Object
compares the complete internal state of two PhotoDetails objects rather than simply comparing object_id’s
25 26 27 |
# File 'lib/flickr_mocks/models/photo_size.rb', line 25 def ==(other) @delegated_to_object == other.instance_eval('@delegated_to_object') end |
#delegated_instance_methods ⇒ Object
returns list of methods that are delegated to other objects
32 33 34 |
# File 'lib/flickr_mocks/models/photo_size.rb', line 32 def delegated_instance_methods @delegated_to_object.methods(false).push(:flickr_type) end |
#id ⇒ Object
returns the flickr id for the given photo
14 15 16 |
# File 'lib/flickr_mocks/models/photo_size.rb', line 14 def id source.split('/')[-1].split('_')[0] end |
#initialize_copy(orig) ⇒ Object
compares value for internal state rather than object_id
57 58 59 60 |
# File 'lib/flickr_mocks/models/photo_size.rb', line 57 def initialize_copy(orig) super @delegated_to_object = @delegated_to_object.clone end |
#methods ⇒ Object
returns delegated methods as well as regular methods
52 53 54 |
# File 'lib/flickr_mocks/models/photo_size.rb', line 52 def methods delegated_instance_methods + old_methods end |
#old_methods ⇒ Object
50 |
# File 'lib/flickr_mocks/models/photo_size.rb', line 50 alias :old_methods :methods |
#old_respond_to? ⇒ Object
43 |
# File 'lib/flickr_mocks/models/photo_size.rb', line 43 alias :old_respond_to? :respond_to? |
#respond_to?(method, type = false) ⇒ Boolean
returns true for delegated and regular methods
45 46 47 48 |
# File 'lib/flickr_mocks/models/photo_size.rb', line 45 def respond_to?(method,type=false) return true if delegated_instance_methods.include?(method) old_respond_to?(method,type) end |
#secret ⇒ Object
returns the flickr secret for the given photo
19 20 21 |
# File 'lib/flickr_mocks/models/photo_size.rb', line 19 def secret source.split('/')[-1].split('_')[1] end |
#size ⇒ Object
returns the string that contains the photo’s size
9 10 11 |
# File 'lib/flickr_mocks/models/photo_size.rb', line 9 def size label.to_s.downcase.sub(/\s+/,'_') end |