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.



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

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)


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

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

#get_1d_array(column_header) ⇒ Object



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

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



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

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



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

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



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

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



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

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



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

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



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

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