Class: Simulator::Data

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#periodsObject

Returns the value of attribute periods.



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

def periods
  @periods
end

Instance Method Details

#series(*var_names) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/simulator/data.rb', line 4

def series(*var_names)
  data = var_names.collect do |var_name|
    @periods.collect do |period|
      var = period.context.get var_name
      var.value unless var.nil?
    end
  end

  # If we just hae one series, then just return the first
  var_names.length == 1 ? data.first : data
end

#series_with_headers(*var_names) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/simulator/data.rb', line 15

def series_with_headers(*var_names)
  data = series *var_names
  table = var_names.zip data
  table.collect do |row|
    row.flatten
  end
end