Class: Simulator::Period
- Inherits:
-
Object
- Object
- Simulator::Period
- Defined in:
- lib/simulator/period.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#previous_periods ⇒ Object
readonly
Returns the value of attribute previous_periods.
-
#run ⇒ Object
readonly
Returns the value of attribute run.
Instance Method Summary collapse
-
#ago(count) ⇒ Object
returns a period count ago.
-
#first ⇒ Object
the first period.
-
#initialize(run, previous_periods = []) ⇒ Period
constructor
A new instance of Period.
-
#previous ⇒ Object
the period before this one.
Constructor Details
#initialize(run, previous_periods = []) ⇒ Period
Returns a new instance of Period.
7 8 9 10 11 |
# File 'lib/simulator/period.rb', line 7 def initialize(run, previous_periods = []) @run = run @previous_periods = previous_periods @context = @previous_periods.empty? ? VariableContext.new : previous.context.clone end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
3 4 5 |
# File 'lib/simulator/period.rb', line 3 def context @context end |
#previous_periods ⇒ Object (readonly)
Returns the value of attribute previous_periods.
5 6 7 |
# File 'lib/simulator/period.rb', line 5 def previous_periods @previous_periods end |
#run ⇒ Object (readonly)
Returns the value of attribute run.
4 5 6 |
# File 'lib/simulator/period.rb', line 4 def run @run end |
Instance Method Details
#ago(count) ⇒ Object
returns a period count ago
24 25 26 |
# File 'lib/simulator/period.rb', line 24 def ago(count) count == 0 ? self : @previous_periods[-count] end |
#first ⇒ Object
the first period
14 15 16 |
# File 'lib/simulator/period.rb', line 14 def first @previous_periods.first end |
#previous ⇒ Object
the period before this one
19 20 21 |
# File 'lib/simulator/period.rb', line 19 def previous @previous_periods.last end |