-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first draft of supplementary details for transaction
- changes line parsing. neccessary for transactions as they can have newlines within their details field - includes initial amount details - includes charges Co-authored-by: Lars Brillert <lars@railslove.com>
- Loading branch information
Maxim
and
Lars Brillert
committed
Apr 9, 2018
1 parent
bad2a01
commit dafcc43
Showing
12 changed files
with
144 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
module Cmxl | ||
module Fields | ||
class TransactionSupplementary < Field | ||
|
||
attr_accessor :source, :initial, :charges | ||
|
||
class << self | ||
def parse(line) | ||
initial = $1 if line.match(initial_parser) | ||
charges = $1 if line.match(charges_parser) | ||
new(line, initial, charges) | ||
end | ||
|
||
def initial_parser; %r{((?:\/OCMT\/)(?<initial>[a-zA-Z]{3}[\d,]{1,15}))} end | ||
def charges_parser; %r{((?:\/CHGS\/)(?<charges>[a-zA-Z]{3}[\d,]{1,15}))} end | ||
end | ||
|
||
|
||
def initialize(line, initial, charges) | ||
self.source = line | ||
self.initial = initial | ||
self.charges = charges | ||
end | ||
|
||
def initial_amount_in_cents | ||
to_amount_in_cents(initial[3..-1]) if initial | ||
end | ||
|
||
def initial_currency | ||
initial[0..2] if initial | ||
end | ||
|
||
def charges_in_cents | ||
to_amount_in_cents(charges[3..-1]) if charges | ||
end | ||
|
||
def charges_currency | ||
charges[0..2] if charges | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'spec_helper' | ||
|
||
describe Cmxl::Fields::TransactionSupplementary do | ||
let(:fixture) { 'Card Transaction/OCMT/CAD47,11/CHGS/EUR123,45' } | ||
|
||
it { expect(described_class.parse(fixture).initial_amount_in_cents).to eql(4711) } | ||
it { expect(described_class.parse(fixture).initial_currency).to eql('CAD') } | ||
|
||
it { expect(described_class.parse(fixture).charges_in_cents).to eql(12345) } | ||
it { expect(described_class.parse(fixture).charges_currency).to eql('EUR') } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
:61:1804090409DR000000000012,34NTRF0000549855700010//025498557/000001 | ||
/OCMT/CAD47,11 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
:61:1804090409DR000000000056,78NTRF0000549855700010//025498557/000001 | ||
/OCMT/CAD47,11/CHGS/EUR1,23 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters