Permalink
Browse files

Add `raw` method to Deposits

  • Loading branch information...
1 parent 0340fa7 commit c9586c27378b5977d096f35755bb91ed48ed97c7 @dvrensk dvrensk committed Nov 30, 2012
Showing with 15 additions and 3 deletions.
  1. +1 −0 README.md
  2. +10 −2 lib/bankgiro_inbetalningar/parser.rb
  3. +4 −1 spec/bankgiro_inbetalningar/parser_spec.rb
View
1 README.md
@@ -59,6 +59,7 @@ payment_1.currency # => "SEK"
payment_2.currency # => nil
```
+The `raw` method is also available on deposit objects.
See the specs for more details.
Files are expected to be ISO-8859-1 (as Bankgirot prefers), but data strings
View
12 lib/bankgiro_inbetalningar/parser.rb
@@ -35,11 +35,18 @@ def line_parser_class
end
def record_line
+ if result.deposit && deposit_line?
+ result.deposit.raw << @line
+ end
if result.deposit && result.payment && payment_line?
result.payment.raw << @line
end
end
+ def deposit_line?
+ payment_line? || %w(05 15).include?(@line[0..1])
+ end
+
def payment_line?
@line[0] == '2'
end
@@ -215,17 +222,18 @@ def payments
end
class Deposit
- attr_accessor :bgno, :currency, :payments, :date
+ attr_accessor :bgno, :currency, :payments, :date, :raw
def initialize
@payments = []
+ @raw = ""
end
end
class Payment
attr_accessor :cents, :references, :currency, :raw, :payer, :sender_bgno, :text, :date, :number
def initialize
@references = []
- @raw = "".force_encoding('iso-8859-1')
+ @raw = ""
end
def payer!
View
5 spec/bankgiro_inbetalningar/parser_spec.rb
@@ -33,14 +33,17 @@ module BankgiroInbetalningar
payment.references.should == ['535765']
payment.currency.should == 'SEK'
payment.cents.should == 500_00
- payment.raw.should == "200000000000 535765000000000000050000230000000000230 \r\n"
end
it "has a date" do
payment.date.should == Date.civil(2004,5,25)
end
it "has a number" do
payment.number.should == "000000000023"
end
+ it "stores the raw data" do
+ payment.raw.should == "200000000000 535765000000000000050000230000000000230 \r\n"
+ result.deposits[3].raw.split(/\r\n/).should == data.encode('utf-8').split(/\r\n/)[50..65]
+ end
end
context "simple OCR payment with address" do

0 comments on commit c9586c2

Please sign in to comment.