Class: Query

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

Instance Attribute 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

Instance Method Details

#keyword_to_urlObject



18
19
20
21
22
23
24
# File 'lib/query.rb', line 18

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

#parse(query_string) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/query.rb', line 5

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)


14
15
16
# File 'lib/query.rb', line 14

def valid_query?
  Runner.keywords.keys.include?(self.keyword) && self.search_query.is_a?(String) && self.max_price.is_a?(Integer) && self.min_price.is_a?(Integer)
end