Class: Importer::Parser::Base
- Inherits:
-
Object
- Object
- Importer::Parser::Base
- Defined in:
- lib/importer/parser/base.rb
Overview
Extend this class if you want to provide a custom parser. You only need to implement run
instance method in subclasses.
To force the importer to use your custom parser use:
Product.import(file, :parser => CustomParserClass)
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Class Method Summary collapse
-
.run(file) ⇒ Object
Creates parser instance and processes the
file
.
Instance Method Summary collapse
-
#initialize(file) ⇒ Base
constructor
A new instance of Base.
-
#run ⇒ Object
This method must be implemented in subclasses.
Constructor Details
#initialize(file) ⇒ Base
Returns a new instance of Base.
22 23 24 25 |
# File 'lib/importer/parser/base.rb', line 22 def initialize(file) @file = file @data = [] end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
20 21 22 |
# File 'lib/importer/parser/base.rb', line 20 def data @data end |
Class Method Details
.run(file) ⇒ Object
Creates parser instance and processes the file
13 14 15 16 17 |
# File 'lib/importer/parser/base.rb', line 13 def run(file) parser = new(file) parser.run parser.data end |
Instance Method Details
#run ⇒ Object
This method must be implemented in subclasses. It is meant to process input @file, and store the results in @data instance variable.
30 31 32 |
# File 'lib/importer/parser/base.rb', line 30 def run raise Exception.new("This method must be implemented in subclasses.") end |