Class: TextDataTools::TextDataFile

Inherits:
Object
  • Object
show all
Defined in:
lib/text-data-tools.rb

Overview

This is a simple class which can interface with the methods of TextFileTools to prevent the user having to specify the file name and other properties of the data file for every call. In a nutshell, create a new instance of this class giving it the filename, and any appropriate options, then call methods from TextFileTools omitting the appropriate arguments.

Instance Method Summary collapse

Constructor Details

#initialize(filename, has_header_line = false, match = /\S+/, header_match = /\S+/) ⇒ TextDataFile

Returns a new instance of TextDataFile.



163
164
165
166
167
168
169
# File 'lib/text-data-tools.rb', line 163

def initialize(filename, has_header_line = false, match = /\S+/, header_match = /\S+/)
  @filename = filename
  @match = match
  @header_match = header_match
  @has_header_line = has_header_line
  self
end

Instance Method Details

#get_1d_array(column_header) ⇒ Object



170
171
172
# File 'lib/text-data-tools.rb', line 170

def get_1d_array(column_header)
  TextFileTools.get_1d_array(@filename, @has_header_line, column_header, @match, @header_match)
end

#get_1d_array_float(column_header) ⇒ Object



173
174
175
# File 'lib/text-data-tools.rb', line 173

def get_1d_array_float(column_header)
  TextFileTools.get_1d_array_float(@filename, @has_header_line, column_header, @match, @header_match)
end

#get_1d_array_integer(column_header) ⇒ Object



176
177
178
# File 'lib/text-data-tools.rb', line 176

def get_1d_array_integer(column_header)
  TextFileTools.get_1d_array_integer(@filename, @has_header_line, column_header, @match, @header_match)
end

#get_2d_array(column_header, index_header) ⇒ Object



179
180
181
# File 'lib/text-data-tools.rb', line 179

def get_2d_array(column_header, index_header)
  TextFileTools.get_2d_array(@filename, @has_header_line, column_header, index_header, @match, @header_match)
end

#get_2d_array_float(column_header, index_header) ⇒ Object



182
183
184
# File 'lib/text-data-tools.rb', line 182

def get_2d_array_float(column_header, index_header)
  TextFileTools.get_2d_array(@filename, @has_header_line, column_header, index_header, @match, @header_match)
end

#get_2d_array_integer(column_header, index_header) ⇒ Object



185
186
187
# File 'lib/text-data-tools.rb', line 185

def get_2d_array_integer(column_header, index_header)
  TextFileTools.get_2d_array(@filename, @has_header_line, column_header, index_header, @match, @header_match)
end

#get_variable_value(name, sep) ⇒ Object



188
189
190
# File 'lib/text-data-tools.rb', line 188

def get_variable_value(name, sep)
  TextFileTools.get_variable_value(@filename, name, sep)
end