Class: LemonadeStand::Event
- Inherits:
-
Object
- Object
- LemonadeStand::Event
show all
- Defined in:
- lib/lemonade_stand/event.rb
Constant Summary
collapse
- DAY_TYPES =
[:sunny, :hot_and_dry, :cloudy]
Class Method Summary
collapse
Class Method Details
.build(type) ⇒ Object
30
31
32
|
# File 'lib/lemonade_stand/event.rb', line 30
def self.build type
eval("LemonadeStand::#{type.to_s.split('_').map { |x| x.capitalize }.join('')}Event").new
end
|
.cloudy_event_for(_) ⇒ Object
19
20
21
22
23
24
|
# File 'lib/lemonade_stand/event.rb', line 19
def self.cloudy_event_for _
if rand(100) < 25
return build(:storm)
end
return build(:rain)
end
|
.for(day) ⇒ Object
7
8
9
10
|
# File 'lib/lemonade_stand/event.rb', line 7
def self.for day
type = DAY_TYPES.select { |x| day.weather.send("#{x}?".to_sym) }.first
send("#{type}_event_for".to_sym, day)
end
|
.hot_and_dry_event_for(_) ⇒ Object
26
27
28
|
# File 'lib/lemonade_stand/event.rb', line 26
def self.hot_and_dry_event_for _
build(:heat_wave)
end
|
.sunny_event_for(day) ⇒ Object
12
13
14
15
16
17
|
# File 'lib/lemonade_stand/event.rb', line 12
def self.sunny_event_for day
if day.number > 2 && rand(100) < 25
return build(:street_work)
end
return build(:normal)
end
|