Class: Query
- Inherits:
-
Object
- Object
- Query
- Defined in:
- lib/query.rb
Instance Attribute Summary collapse
-
#keyword ⇒ Object
Returns the value of attribute keyword.
-
#max_price ⇒ Object
Returns the value of attribute max_price.
-
#min_price ⇒ Object
Returns the value of attribute min_price.
-
#search_query ⇒ Object
Returns the value of attribute search_query.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ Query
constructor
A new instance of Query.
- #keyword_to_url ⇒ Object
- #parse(query_string) ⇒ Object
- #valid_query? ⇒ Boolean
Constructor Details
#initialize(args = {}) ⇒ Query
Returns a new instance of Query.
20 21 22 23 24 25 |
# File 'lib/query.rb', line 20 def initialize(args = {}) @keyword = args.fetch(:keyword, "nyc") @search_query = args.fetch(:search_query, "bookshelf") @min_price = args.fetch(:min_price, 0) @max_price = args.fetch(:max_price, 2000) end |
Instance Attribute Details
#keyword ⇒ Object
Returns the value of attribute keyword.
3 4 5 |
# File 'lib/query.rb', line 3 def keyword @keyword end |
#max_price ⇒ Object
Returns the value of attribute max_price.
3 4 5 |
# File 'lib/query.rb', line 3 def max_price @max_price end |
#min_price ⇒ Object
Returns the value of attribute min_price.
3 4 5 |
# File 'lib/query.rb', line 3 def min_price @min_price end |
#search_query ⇒ Object
Returns the value of attribute search_query.
3 4 5 |
# File 'lib/query.rb', line 3 def search_query @search_query end |
Class Method Details
.keywords ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/query.rb', line 5 def self.keywords { "mnh" => "Manhattan", "brk" => "Brooklyn", "que" => "Queens", "brx" => "The Bronx", "stn" => "Staten Island", "jsy" => "New Jersey", "lgi" => "Long Island", "wch" => "Westchester", "fct" => "Fairfield", "nyc" => "New York City", } end |
Instance Method Details
#keyword_to_url ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/query.rb', line 40 def keyword_to_url if keyword == "nyc" "" else "/#{keyword}" end end |
#parse(query_string) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/query.rb', line 27 def parse(query_string) query_array = query_string.split(" ") self.keyword = query_array.shift self.max_price = query_array.pop.to_i self.min_price = query_array.pop.to_i self.search_query = query_array.join(" ") return self end |
#valid_query? ⇒ Boolean
36 37 38 |
# File 'lib/query.rb', line 36 def valid_query? Query.keywords.keys.include?(self.keyword) && self.search_query.is_a?(String) && self.max_price.is_a?(Integer) && self.min_price.is_a?(Integer) end |