Class: TextDataTools::Column::DataFile

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

Overview

This is a simple class which can interface with the methods of TextDataTools::Column 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 TextDataTools omitting the appropriate arguments.

Instance Method Summary collapse

Methods inherited from DataFileBase

#to_s, #view

Constructor Details

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

Returns a new instance of DataFile.



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

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

#exists?Boolean

Returns:

  • (Boolean)


195
196
197
# File 'lib/text-data-tools.rb', line 195

def exists?
	FileTest.exists?(@filename)
end

#get_1d_array(column_header) ⇒ Object



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

def get_1d_array(column_header)
	TextDataTools::Column.get_1d_array(@filename, @has_header_line, column_header, @match, @header_match)
end

#get_1d_array_float(column_header) ⇒ Object



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

def get_1d_array_float(column_header)
	TextDataTools::Column.get_1d_array_float(@filename, @has_header_line, column_header, @match, @header_match)
end

#get_1d_array_integer(column_header) ⇒ Object



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

def get_1d_array_integer(column_header)
	TextDataTools::Column.get_1d_array_integer(@filename, @has_header_line, column_header, @match, @header_match)
end

#get_2d_array(column_header, index_header) ⇒ Object



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

def get_2d_array(column_header, index_header)
	TextDataTools::Column.get_2d_array(@filename, @has_header_line, column_header, index_header, @match, @header_match)
end

#get_2d_array_float(column_header, index_header) ⇒ Object



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

def get_2d_array_float(column_header, index_header)
	TextDataTools::Column.get_2d_array_float(@filename, @has_header_line, column_header, index_header, @match, @header_match)
end

#get_2d_array_integer(column_header, index_header) ⇒ Object



192
193
194
# File 'lib/text-data-tools.rb', line 192

def get_2d_array_integer(column_header, index_header)
	TextDataTools::Column.get_2d_array_integer(@filename, @has_header_line, column_header, index_header, @match, @header_match)
end

#inspectObject



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

def inspect
	"#{self.class}.new(#{@filename.inspect}, #{@has_header_line.inspect}, #{@match.inspect}, #{@header_match.inspect})"
end