Class: OpenTox::Parser::Spreadsheets

Inherits:
Object
  • Object
show all
Defined in:
lib/parser.rb

Overview

Parser for getting spreadsheet data into a dataset

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSpreadsheets

Returns a new instance of Spreadsheets.



247
248
249
250
251
252
253
254
255
256
# File 'lib/parser.rb', line 247

def initialize
  @data = []
  @features = []
  @feature_types = {}

  @format_errors = ""
  @smiles_errors = []
  @activity_errors = []
  @duplicates = {}
end

Instance Attribute Details

#datasetObject

Returns the value of attribute dataset.



245
246
247
# File 'lib/parser.rb', line 245

def dataset
  @dataset
end

Instance Method Details

#load_csv(csv) ⇒ OpenTox::Dataset

Load CSV string (format specification: toxcreate.org/help)

Parameters:

  • csv (String)

    CSV representation of the dataset

Returns:



272
273
274
275
276
277
278
279
# File 'lib/parser.rb', line 272

def load_csv(csv)
  row = 0
  input = csv.split("\n")
  add_features split_row(input.shift)
  input.each { |row| add_values split_row(row) }
  warnings
  @dataset
end

#load_spreadsheet(book) ⇒ OpenTox::Dataset

Load Spreadsheet book (created with roo gem roo.rubyforge.org/, excel format specification: toxcreate.org/help)

Parameters:

  • book (Excel)

    Excel workbook object (created with roo gem)

Returns:



261
262
263
264
265
266
267
# File 'lib/parser.rb', line 261

def load_spreadsheet(book)
  book.default_sheet = 0
  add_features book.row(1)
  2.upto(book.last_row) { |i| add_values book.row(i) }
  warnings
  @dataset
end