Class: Stockboy::Reader Abstract
- Inherits:
-
Object
- Object
- Stockboy::Reader
- Extended by:
- DSL
- Defined in:
- lib/stockboy/reader.rb
Overview
This class is abstract.
Abstract class for defining data readers
Interface
A reader must implement a parse
method for extracting an array of records from raw data. At this stage no data transformation is performed, only extracting field tokens for each record, based on the specific data serialization.
String keys should be preferred, since these may be specified by the user; external inputs should not be symbolized (because symbols are never GC’d). Frozen strings for keys are a good idea, of course.
Direct Known Subclasses
Stockboy::Readers::CSV, Stockboy::Readers::FixedWidth, Stockboy::Readers::Spreadsheet, Stockboy::Readers::XML
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Reader
constructor
Initialize a new reader.
-
#parse(data) ⇒ Array<Hash>
Take raw input (String) and extract an array of records.
Constructor Details
#initialize(opts = {}) ⇒ Reader
Initialize a new reader
31 32 33 |
# File 'lib/stockboy/reader.rb', line 31 def initialize(opts={}) @encoding = opts.delete(:encoding) end |
Instance Method Details
#parse(data) ⇒ Array<Hash>
Take raw input (String) and extract an array of records
39 40 41 |
# File 'lib/stockboy/reader.rb', line 39 def parse(data) raise NoMethodError, "#{self.class}#parse needs implementation" end |