class Query
Attributes
keyword[RW]
max_price[RW]
min_price[RW]
search_query[RW]
Public Class Methods
keywords()
click to toggle source
# 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
new(args = {})
click to toggle source
# 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
Public Instance Methods
keyword_to_url()
click to toggle source
# File lib/query.rb, line 40 def keyword_to_url if keyword == "nyc" "" else "/#{keyword}" end end
parse(query_string)
click to toggle source
# 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?()
click to toggle source
# 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