Class: Treyja::Command::Csv

Inherits:
Object
  • Object
show all
Defined in:
lib/treyja/command/csv.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

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

#runObject



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