Class: DataImport::BaseParser
- Inherits:
-
Object
- Object
- DataImport::BaseParser
- Defined in:
- app/services/data_import/base_parser.rb
Overview
Service object: base parser.
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.
6 7 8 9 10 11 12 |
# File 'app/services/data_import/base_parser.rb', line 6 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.
4 5 6 |
# File 'app/services/data_import/base_parser.rb', line 4 def file_name @file_name end |
#file_path ⇒ Object (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 |
#format ⇒ Object (readonly)
Returns the value of attribute format.
4 5 6 |
# File 'app/services/data_import/base_parser.rb', line 4 def format @format end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'app/services/data_import/base_parser.rb', line 4 def @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, = {}) format = .delete(:format) format ||= File.extname(file_name)[1..].to_sym parserKlass = "DataImport::#{format.to_s.titleize}Parser".constantize parserKlass.new(file_path, file_name, ) end |
Instance Method Details
#column_names ⇒ Object
18 19 20 |
# File 'app/services/data_import/base_parser.rb', line 18 def column_names raise "Not Implemented" end |
#each_with_index ⇒ Object
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
29 30 31 |
# File 'app/services/data_import/base_parser.rb', line 29 def first_row_is_header? [:first_row_is_header] end |
#size ⇒ Object
37 38 39 |
# File 'app/services/data_import/base_parser.rb', line 37 def size raise "Not Implemented" end |
#validate ⇒ Object
33 34 35 |
# File 'app/services/data_import/base_parser.rb', line 33 def validate raise "Not Implemented" end |