Class: FlickrMocks::Models::PhotoSearch
- Inherits:
-
Object
- Object
- FlickrMocks::Models::PhotoSearch
- Defined in:
- lib/flickr_mocks/models/photo_search.rb
Class Attribute Summary collapse
-
.delegated_instance_methods ⇒ Object
Returns the value of attribute delegated_instance_methods.
Instance Attribute Summary collapse
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#search_terms ⇒ Object
readonly
Returns the value of attribute search_terms.
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.
-
#extract_date(options) ⇒ Object
returns the date stored in the :date key for the supplied options hash.
-
#extract_page(options) ⇒ Object
returns the sanitized version of the value stored in the :page key for the supplied options hash.
-
#extract_search_terms(options) ⇒ Object
returns the string stored in the :search_terms key for the supplied options hash.
-
#initialize(data, options = {}) ⇒ PhotoSearch
constructor
A new instance of PhotoSearch.
-
#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
-
#photos ⇒ Object
returns Photos object that contains information regarding the photos returned from Flickr.
-
#respond_to?(method) ⇒ Boolean
returns true for delegated and regular methods.
-
#total_results ⇒ Object
returns the total number of results available from Flickr for the given photo.
-
#url_params ⇒ Object
returns hash of parameters that were used for performing the query.
Constructor Details
#initialize(data, options = {}) ⇒ PhotoSearch
Returns a new instance of PhotoSearch.
13 14 15 16 17 18 |
# File 'lib/flickr_mocks/models/photo_search.rb', line 13 def initialize(data,={}) self.delegated_to_object = data @search_terms = extract_search_terms() @page = extract_page().to_i @date = extract_date() 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. It also delegates array methods to the @dimensions object
87 88 89 90 91 |
# File 'lib/flickr_mocks/models/photo_search.rb', line 87 def method_missing(id,*args,&block) return photos.photos.send(id,*args,&block) if delegated_array_accessor_methods.include?(id) return photos.send(id,*args,&block) if delegated_instance_methods.include?(id) super end |
Class Attribute Details
.delegated_instance_methods ⇒ Object
Returns the value of attribute delegated_instance_methods.
10 11 12 |
# File 'lib/flickr_mocks/models/photo_search.rb', line 10 def delegated_instance_methods @delegated_instance_methods end |
Instance Attribute Details
#date ⇒ Object (readonly)
Returns the value of attribute date.
4 5 6 |
# File 'lib/flickr_mocks/models/photo_search.rb', line 4 def date @date end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
4 5 6 |
# File 'lib/flickr_mocks/models/photo_search.rb', line 4 def page @page end |
#search_terms ⇒ Object (readonly)
Returns the value of attribute search_terms.
4 5 6 |
# File 'lib/flickr_mocks/models/photo_search.rb', line 4 def search_terms @search_terms end |
Instance Method Details
#==(other) ⇒ Object
compares the complete internal state of two PhotoDetails objects rather than simply comparing object_id’s
76 77 78 79 80 81 |
# File 'lib/flickr_mocks/models/photo_search.rb', line 76 def ==(other) return false unless other.class == self.class (photos == other.photos) && [:search_terms,:page,:date].inject(true) do |state,method| state && (self.send(method) == other.send(method)) end end |
#delegated_instance_methods ⇒ Object
returns list of methods that are delegated to other objects
106 107 108 |
# File 'lib/flickr_mocks/models/photo_search.rb', line 106 def delegated_instance_methods PhotoSearch.delegated_instance_methods + delegated_array_accessor_methods end |
#extract_date(options) ⇒ Object
returns the date stored in the :date key for the supplied options hash. Values other than nil and strings of format ‘YYYY-MM-DD’ will raise an argument error. Sample usage:
extract_date(:date => '2010-10-10') --> '2010-10-10'
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/flickr_mocks/models/photo_search.rb', line 36 def extract_date() date = [:date] case date when NilClass nil when String Api::Helpers.valid_date?(date) ? Api::Helpers.date(date) : raise(ArgumentError) else raise ArgumentError end end |
#extract_page(options) ⇒ Object
returns the sanitized version of the value stored in the :page key for the supplied options hash.
50 51 52 |
# File 'lib/flickr_mocks/models/photo_search.rb', line 50 def extract_page() Api::Sanitize.page([:page]) end |
#extract_search_terms(options) ⇒ Object
returns the string stored in the :search_terms key for the supplied options hash. The string is stripped of non-required spaces and is made to be lower case. Sample usage:
extract_search_terms(:search_terms => 'Lyon , France' --> 'lyon,france'
27 28 29 |
# File 'lib/flickr_mocks/models/photo_search.rb', line 27 def extract_search_terms() Api::Sanitize.([:search_terms]) end |
#initialize_copy(other) ⇒ Object
compares value for internal state rather than object_id
112 113 114 115 |
# File 'lib/flickr_mocks/models/photo_search.rb', line 112 def initialize_copy(other) super @delegated_to_object = @delegated_to_object.clone end |
#methods ⇒ Object
returns delegated methods as well as regular methods
101 102 103 |
# File 'lib/flickr_mocks/models/photo_search.rb', line 101 def methods delegated_instance_methods + old_methods end |
#old_methods ⇒ Object
99 |
# File 'lib/flickr_mocks/models/photo_search.rb', line 99 alias :old_methods :methods |
#old_respond_to? ⇒ Object
93 |
# File 'lib/flickr_mocks/models/photo_search.rb', line 93 alias :old_respond_to? :respond_to? |
#photos ⇒ Object
returns Photos object that contains information regarding the photos returned from Flickr
57 58 59 |
# File 'lib/flickr_mocks/models/photo_search.rb', line 57 def photos @delegated_to_object end |
#respond_to?(method) ⇒ Boolean
returns true for delegated and regular methods
95 96 97 |
# File 'lib/flickr_mocks/models/photo_search.rb', line 95 def respond_to?(method) delegated_instance_methods.include?(method) || old_respond_to?(method) end |
#total_results ⇒ Object
returns the total number of results available from Flickr for the given photo. note flickr only returns 4,000 maximum for a given query.
63 64 65 |
# File 'lib/flickr_mocks/models/photo_search.rb', line 63 def total_results total_entries end |
#url_params ⇒ Object
returns hash of parameters that were used for performing the query.
68 69 70 71 72 |
# File 'lib/flickr_mocks/models/photo_search.rb', line 68 def url_params { :search_terms => search_terms, :date => (date.nil? && (search_terms.nil? || search_terms.empty?)) ? Api::Helpers.date : date }.keep_if do |k,v| !(v.nil? || v.to_s.empty?) end end |