Class: DataImport::BaseParser

Inherits:
Object
  • Object
show all
Defined in:
app/services/data_import/base_parser.rb

Direct Known Subclasses

CsvParser, XlsxParser

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path, file_name, options = {}) ⇒ BaseParser

Returns a new instance of BaseParser.



4
5
6
7
8
9
# File 'app/services/data_import/base_parser.rb', line 4

def initialize(file_path, file_name, options={})
  raise "File not found" unless file_path && File.exist?(file_path)
  @file_path = file_path
  @options = options
  @file_name = file_name
end

Instance Attribute Details

#file_nameObject (readonly)

Returns the value of attribute file_name.



2
3
4
# File 'app/services/data_import/base_parser.rb', line 2

def file_name
  @file_name
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



2
3
4
# File 'app/services/data_import/base_parser.rb', line 2

def file_path
  @file_path
end

#formatObject (readonly)

Returns the value of attribute format.



2
3
4
# File 'app/services/data_import/base_parser.rb', line 2

def format
  @format
end

#optionsObject (readonly)

Returns the value of attribute options.



2
3
4
# File 'app/services/data_import/base_parser.rb', line 2

def options
  @options
end

Class Method Details

.instantiate(file_path, file_name, options = {}) ⇒ Object



19
20
21
22
23
24
# File 'app/services/data_import/base_parser.rb', line 19

def self.instantiate(file_path, file_name, options = {})
  format = options.delete(:format)
  format ||= File.extname(file_name)[1..-1].to_sym
  parserKlass = "DataImport::#{format.to_s.titleize}Parser".constantize
  parserKlass.new(file_path, file_name, options)
end

Instance Method Details

#column_namesObject



15
16
17
# File 'app/services/data_import/base_parser.rb', line 15

def column_names
  raise "Not Implemented"
end

#each_with_indexObject



11
12
13
# File 'app/services/data_import/base_parser.rb', line 11

def each_with_index
  raise "Not Implemented"
end

#first_row_is_header?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'app/services/data_import/base_parser.rb', line 26

def first_row_is_header?
  options[:first_row_is_header]
end

#sizeObject



34
35
36
# File 'app/services/data_import/base_parser.rb', line 34

def size
  raise "Not Implemented"
end

#validateObject



30
31
32
# File 'app/services/data_import/base_parser.rb', line 30

def validate
  raise "Not Implemented"
end