Class: TorQML::DataSources::CSVDataSource_rb
- Inherits:
-
MatrixDataSource_rb
- Object
- DataSource_rb
- MatrixDataSource_rb
- TorQML::DataSources::CSVDataSource_rb
- Includes:
- QML::Access
- Defined in:
- lib/torqml/datasources/csvdatasource.rb
Overview
Data source class to provide CSV data.
Instance Method Summary collapse
-
#prepare_data ⇒ Object
Prepare data to provide.
-
#separator ⇒ String
The separator character of the CSV file.
-
#source ⇒ String
The file path.
Methods inherited from MatrixDataSource_rb
Methods inherited from DataSource_rb
#currentFrame, #rows, #value_at
Instance Method Details
#prepare_data ⇒ Object
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 |
#separator ⇒ String
Returns the separator character of the CSV file.
18 |
# File 'lib/torqml/datasources/csvdatasource.rb', line 18 property(:separator) { "" } |
#source ⇒ String
Returns the file path.
16 |
# File 'lib/torqml/datasources/csvdatasource.rb', line 16 property(:source) { "" } |