Class: FuzzyRealty::Query

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = []) ⇒ Query

Returns a new instance of Query.



4
5
6
7
8
9
# File 'lib/classes.rb', line 4

def initialize(params=[])
  if params.any? {|param| !param.is_a?(Parameter)}
    raise "Attempting to add non-Parameter to Query"
  end
  @params = params
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



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

def params
  @params
end

Class Method Details

.randomObject

Create a random query for testing



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/classes.rb', line 19

def self.random
  query = Query.new
  query << Parameter.new(:price, 20_000 + rand(250_000),  [true,false][rand(1)])
  query << Parameter.new(:sqft,  300 + rand(2000),        [true,false][rand(1)])
  query << Parameter.new(:location, %W{A B C D}[rand(4)], [true,false][rand(1)])
  query << Parameter.new(
    :style,   
    %W{Bungalow Bi-level Split-level Two-story Condominium}[rand(5)],
    [true,false][rand(1)])
  query
end

Instance Method Details

#<<(param) ⇒ Object

Allows formation of Query by ‘popping’ parameters onto it



11
12
13
14
15
16
# File 'lib/classes.rb', line 11

def << (param)
  if !param.is_a?(Parameter)
    raise "Attempting to add non-Parameter to Query" 
  end
  @params << param
end