Class: Fortune::EventList
- Inherits:
-
Array
- Object
- Array
- Fortune::EventList
- Defined in:
- lib/fortune/event_list.rb
Instance Attribute Summary collapse
-
#intervals ⇒ Object
Returns the value of attribute intervals.
-
#n ⇒ Object
Returns the value of attribute n.
-
#sum_m ⇒ Object
Returns the value of attribute sum_m.
Instance Method Summary collapse
- #active ⇒ Object
- #calc ⇒ Object
- #calc_intervals ⇒ Object
- #calc_sum_m ⇒ Object
- #get_n ⇒ Object
-
#initialize(h = {}) ⇒ EventList
constructor
A new instance of EventList.
- #set_active ⇒ Object
Constructor Details
Instance Attribute Details
#intervals ⇒ Object
Returns the value of attribute intervals.
4 5 6 |
# File 'lib/fortune/event_list.rb', line 4 def intervals @intervals end |
#n ⇒ Object
Returns the value of attribute n.
4 5 6 |
# File 'lib/fortune/event_list.rb', line 4 def n @n end |
#sum_m ⇒ Object
Returns the value of attribute sum_m.
4 5 6 |
# File 'lib/fortune/event_list.rb', line 4 def sum_m @sum_m end |
Instance Method Details
#active ⇒ Object
40 41 42 |
# File 'lib/fortune/event_list.rb', line 40 def active self.select{|event| event.has_come?}.first end |
#calc ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/fortune/event_list.rb', line 10 def calc self.calc_sum_m self.calc_intervals self.get_n self.set_active self end |
#calc_intervals ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/fortune/event_list.rb', line 32 def calc_intervals x = 0 self.map{|event| next if event.m <= 0 self.intervals[event.name] = [x + 1, x + event.m] x = x + event.m } end |
#calc_sum_m ⇒ Object
26 27 28 29 30 31 |
# File 'lib/fortune/event_list.rb', line 26 def calc_sum_m self.map{|event| next if event.m <= 0 self.sum_m += event.m } end |
#get_n ⇒ Object
23 24 25 |
# File 'lib/fortune/event_list.rb', line 23 def get_n @n = P.n(self.sum_m) end |
#set_active ⇒ Object
17 18 19 20 21 22 |
# File 'lib/fortune/event_list.rb', line 17 def set_active self.map{|event| next if event.m <= 0 event.set_come if self.n >= intervals[event.name][0] && self.n <= intervals[event.name][1] } end |