Class: Simulator::Period

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#contextObject (readonly)

Returns the value of attribute context.



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

def context
  @context
end

#previous_periodsObject (readonly)

Returns the value of attribute previous_periods.



5
6
7
# File 'lib/simulator/period.rb', line 5

def previous_periods
  @previous_periods
end

#runObject (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

#firstObject

the first period



14
15
16
# File 'lib/simulator/period.rb', line 14

def first
  @previous_periods.first
end

#previousObject

the period before this one



19
20
21
# File 'lib/simulator/period.rb', line 19

def previous
  @previous_periods.last
end