Class: Razsell::Query
- Inherits:
-
Object
- Object
- Razsell::Query
- Includes:
- ImageSizes, SortMethods
- Defined in:
- lib/query.rb
Constant Summary
Constants included from ImageSizes
ImageSizes::HUGE, ImageSizes::LARGE, ImageSizes::MEDIUM, ImageSizes::SMALL, ImageSizes::TINY
Constants included from SortMethods
SortMethods::DATE_CREATED, SortMethods::POPULARITY
Instance Attribute Summary collapse
-
#artist ⇒ Object
readonly
Returns the value of attribute artist.
-
#page_limit ⇒ Object
Returns the value of attribute page_limit.
Instance Method Summary collapse
- #advance_page ⇒ Object
-
#base_url ⇒ Object
def add_criteria name, value this.send name, value end.
- #for_artist(artist) ⇒ Object
-
#initialize(*args) ⇒ Query
constructor
A new instance of Query.
- #to_querystring ⇒ Object
- #to_url ⇒ Object
Constructor Details
#initialize(*args) ⇒ Query
Returns a new instance of Query.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/query.rb', line 12 def initialize *args set_default_page_limit \ default_criteria @keys = { :keywords => 'qs', :product_line => 'cg', :product_type => 'pt', :sort_type => 'st', :sort_period => 'sp', :page => 'pg', :items_per_page => 'ps', :feed_type => 'ft', :image_size => 'isz', :image_background_color => 'bg', :opensearch => 'opensearch', :source => 'src'} end |
Instance Attribute Details
#artist ⇒ Object (readonly)
Returns the value of attribute artist.
10 11 12 |
# File 'lib/query.rb', line 10 def artist @artist end |
#page_limit ⇒ Object
Returns the value of attribute page_limit.
9 10 11 |
# File 'lib/query.rb', line 9 def page_limit @page_limit end |
Instance Method Details
#advance_page ⇒ Object
45 46 47 48 49 50 |
# File 'lib/query.rb', line 45 def advance_page return false if @querystring[:page] >= page_limit @querystring[:page] = @querystring[:page] + 1 true end |
#base_url ⇒ Object
def add_criteria name, value
this.send name, value
end
32 33 34 35 |
# File 'lib/query.rb', line 32 def base_url return "http://feed.zazzle.com/#{@artist}/rss" if @artist "http://feed.zazzle.com/rss" end |
#for_artist(artist) ⇒ Object
23 24 25 26 |
# File 'lib/query.rb', line 23 def for_artist artist @artist = artist self end |
#to_querystring ⇒ Object
37 38 39 |
# File 'lib/query.rb', line 37 def to_querystring @querystring.to_a.map { |a| build_pair(a) }.sort {|x,y| x <=> y }.delete_if { |pair| pair == "" }.join("&") end |
#to_url ⇒ Object
41 42 43 |
# File 'lib/query.rb', line 41 def to_url "#{base_url}?#{to_querystring}" end |