Class: Treyja::Command::Csv
- Inherits:
-
Object
- Object
- Treyja::Command::Csv
- Defined in:
- lib/treyja/command/csv.rb
Instance Attribute Summary collapse
-
#reader ⇒ Object
readonly
Returns the value of attribute reader.
Instance Method Summary collapse
-
#initialize(reader) ⇒ Csv
constructor
A new instance of Csv.
- #run ⇒ Object
Constructor Details
#initialize(reader) ⇒ Csv
Returns a new instance of Csv.
6 7 8 |
# File 'lib/treyja/command/csv.rb', line 6 def initialize reader @reader = reader end |
Instance Attribute Details
#reader ⇒ Object (readonly)
Returns the value of attribute reader.
4 5 6 |
# File 'lib/treyja/command/csv.rb', line 4 def reader @reader end |
Instance Method Details
#run ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/treyja/command/csv.rb', line 10 def run if head = reader.first headers = head.tensors.each_with_index.flat_map do |t, i| dims_to_indices(t.dims).map do |ix| [i.to_s, ix.empty? ? nil : ix.reverse.map(&:to_s).join('_')].compact.join('-') end end puts headers.join(',') puts head.tensors.flat_map { |t| raw_data(t) }.map(&:to_s).join(',') reader.each do |ts| puts ts.tensors.flat_map { |t| raw_data(t) }.map(&:to_s).join(',') end end end |