Class: Optimus::StimtimesWriter
- Inherits:
-
Object
- Object
- Optimus::StimtimesWriter
- Includes:
- Transformers
- Defined in:
- lib/writers/stimtimes_writer.rb
Constant Summary collapse
- @@computed_columns =
[]
- @@counter_columns =
[]
- @@copydown_columns =
[]
- @@runs =
0
- @@run_column =
''
- @@output_files =
[]
Class Method Summary collapse
- .computed_column(*args) ⇒ Object
- .copydown_column(*args) ⇒ Object
- .counter_column(*args) ⇒ Object
- .output_file(*args) ⇒ Object
- .run_column(col_name) ⇒ Object
- .runs(runs) ⇒ Object
Instance Method Summary collapse
-
#initialize(argv) ⇒ StimtimesWriter
constructor
A new instance of StimtimesWriter.
- #output_file(filename, filter, output_column) ⇒ Object
Constructor Details
#initialize(argv) ⇒ StimtimesWriter
Returns a new instance of StimtimesWriter.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/writers/stimtimes_writer.rb', line 26 def initialize(argv) # Look through our necessary class variables and do some odd stuff edata = Optimus::Data.new argv.each do |filename| File.open(filename, 'r') do |f| reader = Optimus::Reader.new(f) edata.merge!(reader.optimus_data) end @calc = ColumnCalculator.new @calc.data = edata @@computed_columns.each do |coldata| @calc.computed_column *coldata end @@counter_columns.each do |coldata| @calc.counter_column *coldata end @@copydown_columns.each do |coldata| @calc.copydown_column *coldata end @@output_files.each do |output| filename, filter, output_column = output self.output_file(filename, filter, output_column) end end end |
Class Method Details
.computed_column(*args) ⇒ Object
74 75 76 |
# File 'lib/writers/stimtimes_writer.rb', line 74 def computed_column(*args) @@computed_columns << args end |
.copydown_column(*args) ⇒ Object
82 83 84 |
# File 'lib/writers/stimtimes_writer.rb', line 82 def copydown_column(*args) @@copydown_columns << args end |
.counter_column(*args) ⇒ Object
78 79 80 |
# File 'lib/writers/stimtimes_writer.rb', line 78 def counter_column(*args) @@counter_columns << args end |
.output_file(*args) ⇒ Object
94 95 96 |
# File 'lib/writers/stimtimes_writer.rb', line 94 def output_file(*args) @@output_files << args end |
.run_column(col_name) ⇒ Object
90 91 92 |
# File 'lib/writers/stimtimes_writer.rb', line 90 def run_column(col_name) @@run_column = col_name end |
.runs(runs) ⇒ Object
86 87 88 |
# File 'lib/writers/stimtimes_writer.rb', line 86 def runs(runs) @@runs = runs end |
Instance Method Details
#output_file(filename, filter, output_column) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/writers/stimtimes_writer.rb', line 57 def output_file(filename, filter, output_column) File.open(filename, 'w') do |file| filtered = RowFilter.new(@calc, filter) 1.upto(@@runs) do |run| run_rows = filtered.find_all {|row| row[@@run_column].to_s == run.to_s}.to_a vals = run_rows.map { |r| r[output_column] } if vals.size == 0 file.puts "**" else file.puts((vals << "*").join(' ')) end end end end |