Class: Stockboy::Reader Abstract
- Inherits:
-
Object
- Object
- Stockboy::Reader
- Extended by:
- DSL
- Defined in:
- lib/stockboy/reader.rb
Overview
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::JSON, Stockboy::Readers::Spreadsheet, Stockboy::Readers::XML
Instance Attribute Summary collapse
-
#encoding ⇒ Object
readonly
Returns the value of attribute encoding.
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
33 34 35 |
# File 'lib/stockboy/reader.rb', line 33 def initialize(opts={}) @encoding = opts.delete(:encoding) end |
Instance Attribute Details
#encoding ⇒ Object (readonly)
Returns the value of attribute encoding.
27 28 29 |
# File 'lib/stockboy/reader.rb', line 27 def encoding @encoding end |
Instance Method Details
#parse(data) ⇒ Array<Hash>
Take raw input (String) and extract an array of records
41 42 43 |
# File 'lib/stockboy/reader.rb', line 41 def parse(data) raise NoMethodError, "#{self.class}#parse needs implementation" end |