Class: CoffeeOutside::Location

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Location

Returns a new instance of Location.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/coffeeoutside/locations.rb', line 9

def initialize(params)
  if params["name"]
    @name = params["name"]
  else
    raise "Location class requires name key"
  end
  @paused = params["paused"] || false
  @nearby_coffee = params["nearby_coffee"] || []
  @url = params["url"] if params["url"]
  @address = params["address"] if params["address"]
  @location_hint = params["location_hint"] if params["location_hint"]

  # Forecast related
  @rainy_day = params["rainy_day"] || false
  @high_limit = params["high_limit"] if params["high_limit"]
  @low_limit = params["low_limit"] if params["low_limit"]

  # Save params for any dispatcher-specific values
  @params = params
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



7
8
9
# File 'lib/coffeeoutside/locations.rb', line 7

def address
  @address
end

#location_hintObject (readonly)

Returns the value of attribute location_hint.



7
8
9
# File 'lib/coffeeoutside/locations.rb', line 7

def location_hint
  @location_hint
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/coffeeoutside/locations.rb', line 7

def name
  @name
end

#nearby_coffeeObject (readonly)

Returns the value of attribute nearby_coffee.



7
8
9
# File 'lib/coffeeoutside/locations.rb', line 7

def nearby_coffee
  @nearby_coffee
end

#urlObject (readonly)

Returns the value of attribute url.



7
8
9
# File 'lib/coffeeoutside/locations.rb', line 7

def url
  @url
end

Instance Method Details

#paused?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/coffeeoutside/locations.rb', line 30

def paused?
  @paused
end

#to_sObject



44
45
46
# File 'lib/coffeeoutside/locations.rb', line 44

def to_s
  @name
end

#weather_appropriate?(forecast) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
40
41
42
# File 'lib/coffeeoutside/locations.rb', line 34

def weather_appropriate?(forecast)
  # TODO: stderr reasons?

  return false if (forecast.rainy? && !@rainy_day) ||
                  (@low_limit && (forecast.temperature < @low_limit)) ||
                  (@high_limit && (forecast.temperature > @high_limit))

  true
end