Class: DataImport::BaseParser

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

Overview

Service object: base parser.

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.



6
7
8
9
10
11
12
# File 'app/services/data_import/base_parser.rb', line 6

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.



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

def file_name
  @file_name
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



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

def file_path
  @file_path
end

#formatObject (readonly)

Returns the value of attribute format.



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

def format
  @format
end

#optionsObject (readonly)

Returns the value of attribute options.



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

def options
  @options
end

Class Method Details

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



22
23
24
25
26
27
# File 'app/services/data_import/base_parser.rb', line 22

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

Instance Method Details

#column_namesObject



18
19
20
# File 'app/services/data_import/base_parser.rb', line 18

def column_names
  raise "Not Implemented"
end

#each_with_indexObject



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

def each_with_index
  raise "Not Implemented"
end

#first_row_is_header?Boolean

Returns:

  • (Boolean)


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

def first_row_is_header?
  options[:first_row_is_header]
end

#sizeObject



37
38
39
# File 'app/services/data_import/base_parser.rb', line 37

def size
  raise "Not Implemented"
end

#validateObject



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

def validate
  raise "Not Implemented"
end