Class: TotalRecall::BankParser

Inherits:
Object
  • Object
show all
Defined in:
lib/total_recall.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ BankParser

Returns a new instance of BankParser.



191
192
193
# File 'lib/total_recall.rb', line 191

def initialize(options={})
  @strategy = options[:strategy]
end

Instance Attribute Details

#strategyObject (readonly)

Returns the value of attribute strategy.



189
190
191
# File 'lib/total_recall.rb', line 189

def strategy
  @strategy
end

Instance Method Details

#parse(str, options = {}) ⇒ Array<Hash>

Parses csv content and returns array of hashes.

Examples:

parser = TotalRecall::BankParser.new(:strategy => TotalRecall::ParseStrategy::Some.new)
parser.parse("12.1\n1.99") #=> [{:amount => 12.1}, {:amount => 1.99}]

Parameters:

  • str (String)

    content of csv to parse.

Returns:

  • (Array<Hash>)


203
204
205
206
207
208
209
# File 'lib/total_recall.rb', line 203

def parse(str, options={})
  options = strategy.options.merge(options)

  result = []
  CSV.parse(str, options){|row| result << strategy.parse_row(row)}
  result
end