class Stockboy::Reader
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.
@example
reader.parse("name,email\nArthur Dent,arthur@example.com") # => [{"name" => "Arthur Dent", "email" => "arthur@example.com"}]
@abstract
Attributes
encoding[R]
Public Class Methods
new(opts={})
click to toggle source
Initialize a new reader
@param [Hash] opts
# File lib/stockboy/reader.rb, line 33 def initialize(opts={}) @encoding = opts.delete(:encoding) end
Public Instance Methods
parse(data)
click to toggle source
Take raw input (String) and extract an array of records
@return [Array<Hash>]
# File lib/stockboy/reader.rb, line 41 def parse(data) raise NoMethodError, "#{self.class}#parse needs implementation" end