Class: DataImport::BaseParser
- Inherits:
-
Object
- Object
- DataImport::BaseParser
- Defined in:
- app/services/data_import/base_parser.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
-
#file_path ⇒ Object
readonly
Returns the value of attribute file_path.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #column_names ⇒ Object
- #each_with_index ⇒ Object
- #first_row_is_header? ⇒ Boolean
-
#initialize(file_path, file_name, options = {}) ⇒ BaseParser
constructor
A new instance of BaseParser.
- #size ⇒ Object
- #validate ⇒ Object
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, ={}) raise "File not found" unless file_path && File.exist?(file_path) @file_path = file_path @options = @file_name = file_name end |
Instance Attribute Details
#file_name ⇒ Object (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_path ⇒ Object (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 |
#format ⇒ Object (readonly)
Returns the value of attribute format.
2 3 4 |
# File 'app/services/data_import/base_parser.rb', line 2 def format @format end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
2 3 4 |
# File 'app/services/data_import/base_parser.rb', line 2 def @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, = {}) format = .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, ) end |
Instance Method Details
#column_names ⇒ Object
15 16 17 |
# File 'app/services/data_import/base_parser.rb', line 15 def column_names raise "Not Implemented" end |
#each_with_index ⇒ Object
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
26 27 28 |
# File 'app/services/data_import/base_parser.rb', line 26 def first_row_is_header? [:first_row_is_header] end |
#size ⇒ Object
34 35 36 |
# File 'app/services/data_import/base_parser.rb', line 34 def size raise "Not Implemented" end |
#validate ⇒ Object
30 31 32 |
# File 'app/services/data_import/base_parser.rb', line 30 def validate raise "Not Implemented" end |