Class: DataFile::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/data_file/reader.rb,
lib/data_file/reader/csv.rb,
lib/data_file/reader/base.rb,
lib/data_file/reader/excel.rb

Defined Under Namespace

Classes: Base, CSV, Excel

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path, options = {}) ⇒ Reader

Returns a new instance of Reader.



7
8
9
10
# File 'lib/data_file/reader.rb', line 7

def initialize(file_path, options = {})
  @options = { headers: true }.merge(options) 
  @file_path = file_path
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



5
6
7
# File 'lib/data_file/reader.rb', line 5

def file
  @file
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



5
6
7
# File 'lib/data_file/reader.rb', line 5

def file_path
  @file_path
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/data_file/reader.rb', line 5

def options
  @options
end

Instance Method Details

#detectorObject



20
21
22
# File 'lib/data_file/reader.rb', line 20

def detector
  @detector ||= Detector.new(file)
end

#parserObject



16
17
18
# File 'lib/data_file/reader.rb', line 16

def parser
  @parser ||= detector.text? ? CSV.new(self) : Excel.new(self)
end