Class: Importer::Parser::Base

Inherits:
Object
  • Object
show all
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)

Direct Known Subclasses

Csv, Xml

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#dataObject (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

#runObject

This method must be implemented in subclasses. It is meant to process input @file, and store the results in @data instance variable.

Raises:

  • (Exception)


30
31
32
# File 'lib/importer/parser/base.rb', line 30

def run
  raise Exception.new("This method must be implemented in subclasses.")
end