Class: FlickrMocks::Models::PhotoDimensions
- Inherits:
-
Object
- Object
- FlickrMocks::Models::PhotoDimensions
- Defined in:
- lib/flickr_mocks/models/photo_dimensions.rb
Class Attribute Summary collapse
-
.regexp_size ⇒ Object
readonly
Returns the value of attribute regexp_size.
Instance Method Summary collapse
-
#==(other) ⇒ Object
compares value for internal state rather than object_id.
-
#available_sizes ⇒ Object
returns array of symbols for the sizes available for a given photo.
-
#collection ⇒ Object
returns a collection of photo sizes that can be used directly for WillPaginate.
-
#delegated_instance_methods ⇒ Object
returns the list of methods that are delegated by object.
-
#dimensions ⇒ Object
returns the array of OpenStruct objects available for the given photo size.
-
#initialize(data) ⇒ PhotoDimensions
constructor
A new instance of PhotoDimensions.
-
#initialize_copy(other) ⇒ Object
compares value for internal state rather than object_id.
-
#method_missing(id, *args, &block) ⇒ Object
delegates methods that are returned by delegated instance method.
-
#methods ⇒ Object
returns delegated methods as well as regular methods.
- #old_methods ⇒ Object
-
#old_respond_to? ⇒ Object
metaprogramming methods.
-
#possible_sizes ⇒ Object
returns array of symbols for possible sizes of a given photo.
-
#respond_to?(method) ⇒ Boolean
returns true for delegated and regular methods.
-
#to_s ⇒ Object
returns a string that encodes the size, width and height for the photo.
Constructor Details
#initialize(data) ⇒ PhotoDimensions
Returns a new instance of PhotoDimensions.
14 15 16 |
# File 'lib/flickr_mocks/models/photo_dimensions.rb', line 14 def initialize(data) self.delegated_to_object = data 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
68 69 70 71 72 |
# File 'lib/flickr_mocks/models/photo_dimensions.rb', line 68 def method_missing(id,*args,&block) return get_size(id,*args,&block) if valid_size?(id) return dimensions.send(id,*args,&block) if delegated_instance_methods.include?(id) super end |
Class Attribute Details
.regexp_size ⇒ Object (readonly)
Returns the value of attribute regexp_size.
11 12 13 |
# File 'lib/flickr_mocks/models/photo_dimensions.rb', line 11 def regexp_size @regexp_size end |
Instance Method Details
#==(other) ⇒ Object
compares value for internal state rather than object_id
54 55 56 57 |
# File 'lib/flickr_mocks/models/photo_dimensions.rb', line 54 def ==(other) return false unless other.class.should == self.class to_s == other.to_s end |
#available_sizes ⇒ Object
returns array of symbols for the sizes available for a given photo
19 20 21 22 23 |
# File 'lib/flickr_mocks/models/photo_dimensions.rb', line 19 def available_sizes map do |dimension| dimension.size end end |
#collection ⇒ Object
returns a collection of photo sizes that can be used directly for WillPaginate.
37 38 39 40 41 42 |
# File 'lib/flickr_mocks/models/photo_dimensions.rb', line 37 def collection @collection ||= ::WillPaginate::Collection.create(1, available_sizes.length, available_sizes.length) do |obj| obj.replace(dimensions) end @collection end |
#delegated_instance_methods ⇒ Object
returns the list of methods that are delegated by object
81 82 83 |
# File 'lib/flickr_mocks/models/photo_dimensions.rb', line 81 def delegated_instance_methods Models::Helpers.array_accessor_methods end |
#dimensions ⇒ Object
returns the array of OpenStruct objects available for the given photo size
32 33 34 |
# File 'lib/flickr_mocks/models/photo_dimensions.rb', line 32 def dimensions @delegated_to_object end |
#initialize_copy(other) ⇒ Object
compares value for internal state rather than object_id
86 87 88 89 90 91 |
# File 'lib/flickr_mocks/models/photo_dimensions.rb', line 86 def initialize_copy(other) super @delegated_to_object = @delegated_to_object.map do |object| object.clone end end |
#methods ⇒ Object
returns delegated methods as well as regular methods
76 77 78 |
# File 'lib/flickr_mocks/models/photo_dimensions.rb', line 76 def methods available_sizes + delegated_instance_methods + old_methods end |
#old_methods ⇒ Object
74 |
# File 'lib/flickr_mocks/models/photo_dimensions.rb', line 74 alias :old_methods :methods |
#old_respond_to? ⇒ Object
metaprogramming methods
60 |
# File 'lib/flickr_mocks/models/photo_dimensions.rb', line 60 alias :old_respond_to? :respond_to? |
#possible_sizes ⇒ Object
returns array of symbols for possible sizes of a given photo. Not every photo will have all of the returned sizes.
27 28 29 |
# File 'lib/flickr_mocks/models/photo_dimensions.rb', line 27 def possible_sizes FlickrMocks::Models::Helpers.possible_sizes end |
#respond_to?(method) ⇒ Boolean
returns true for delegated and regular methods
63 64 65 |
# File 'lib/flickr_mocks/models/photo_dimensions.rb', line 63 def respond_to?(method) valid_size?(method) || delegated_instance_methods.include?(method) || old_respond_to?(method) end |
#to_s ⇒ Object
returns a string that encodes the size, width and height for the photo. Sample string returned would be:
"small:100x200,large:300x500" --> ie small photo, width of 100 and lenght of 200
47 48 49 50 51 |
# File 'lib/flickr_mocks/models/photo_dimensions.rb', line 47 def to_s dimensions.map do |dimension| [dimension.size,[dimension.width,dimension.height].join('x')].join(':') end.join(',') end |