Class: TorQML::DataSources::CSVDataSource_rb

Inherits:
MatrixDataSource_rb show all
Includes:
QML::Access
Defined in:
lib/torqml/datasources/csvdatasource.rb

Overview

Data source class to provide CSV data.

Instance Method Summary collapse

Methods inherited from MatrixDataSource_rb

#rows, #value_at

Methods inherited from DataSource_rb

#currentFrame, #rows, #value_at

Instance Method Details

#prepare_dataObject

Prepare data to provide. The separator of CSV data can be set via ‘:separator` property. If not set, the method tries to detect it automatically.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/torqml/datasources/csvdatasource.rb', line 23

def prepare_data
  if self.separator.empty?
    # detect the separator of data
    File.open(self.source, "r") do |file|
      row = file.readline
      if row.match(/,/)
        self.separator = ','
      elsif row.match(/\t/)
        self.separator = '\t'
      elsif row.match(/\s/)
        self.separator = ' '
      end
    end
  end
  @data = CSV.read(self.source, {:converters => :float, :col_sep => self.separator})
end

#separatorString

Returns the separator character of the CSV file.

Returns:

  • (String)

    the separator character of the CSV file



18
# File 'lib/torqml/datasources/csvdatasource.rb', line 18

property(:separator) { "" }

#sourceString

Returns the file path.

Returns:

  • (String)

    the file path



16
# File 'lib/torqml/datasources/csvdatasource.rb', line 16

property(:source) { "" }