Class: Query

Inherits:
Object
  • Object
show all
Defined in:
lib/query.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#keywordObject

Returns the value of attribute keyword.



3
4
5
# File 'lib/query.rb', line 3

def keyword
  @keyword
end

#max_priceObject

Returns the value of attribute max_price.



3
4
5
# File 'lib/query.rb', line 3

def max_price
  @max_price
end

#min_priceObject

Returns the value of attribute min_price.



3
4
5
# File 'lib/query.rb', line 3

def min_price
  @min_price
end

#search_queryObject

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

.keywordsObject



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_urlObject



33
34
35
36
37
38
39
# File 'lib/query.rb', line 33

def keyword_to_url
  if keyword == "nyc"
    ""
  else
    "/#{keyword}"
  end
end

#parse(query_string) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/query.rb', line 20

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

Returns:

  • (Boolean)


29
30
31
# File 'lib/query.rb', line 29

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