-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
142 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
camt_parser (2.15.1) | ||
camt_parser (2.16.0) | ||
nokogiri | ||
|
||
GEM | ||
|
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,51 @@ | ||
module CamtParser | ||
class PostalAddress | ||
|
||
attr_reader :xml_data | ||
|
||
def initialize(xml_data) | ||
@xml_data = xml_data | ||
end | ||
|
||
# @return [Boolean] | ||
def structured? | ||
street_name != "" || | ||
building_number != "" || | ||
postal_code != "" || | ||
town_name != "" | ||
end | ||
|
||
# @return [Array<String>] | ||
def lines # May be empty | ||
xml_data.xpath('AdrLine').map do |x| | ||
x.xpath('text()').text | ||
end | ||
end | ||
|
||
# @return [String] | ||
def street_name # May be missing | ||
xml_data.xpath('StrtNm/text()').text | ||
end | ||
|
||
# @return [String] | ||
def building_number # May be missing | ||
xml_data.xpath('BldgNb/text()').text | ||
end | ||
|
||
# @return [String] | ||
def postal_code # May be missing | ||
xml_data.xpath('PstCd/text()').text | ||
end | ||
|
||
# @return [String] | ||
def town_name # May be missing | ||
xml_data.xpath('TwnNm/text()').text | ||
end | ||
|
||
# @return [String] | ||
def country # May be missing | ||
xml_data.xpath('Ctry/text()').text | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module CamtParser | ||
VERSION = '2.15.1'.freeze | ||
VERSION = '2.16.0'.freeze | ||
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,42 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe CamtParser::PostalAddress do | ||
let(:camt) { CamtParser::File.parse('spec/fixtures/053/valid_example.xml') } | ||
let(:statements) { camt.statements } | ||
let(:ex_stmt) { statements[0] } | ||
let(:entries) { ex_stmt.entries } | ||
let(:ex_entry) { entries[0] } | ||
let(:transactions) { ex_entry.transactions } | ||
let(:ex_transaction) { transactions[0] } | ||
let(:address) { ex_transaction.postal_address } | ||
|
||
specify { expect(address.lines).to eq(["Berlin", "Infinite Loop 2", "12345"]) } | ||
specify { expect(address.structured?).to eq(false) } | ||
specify { expect(address.xml_data).to_not be_nil } | ||
|
||
context "version 8" do | ||
let(:camt) { CamtParser::File.parse('spec/fixtures/053/valid_example_v8.xml') } | ||
let(:ex_entry) { entries[2] } | ||
|
||
specify { expect(address.lines).to eq(["Hochstrasse 5", "4052 Basel"]) } | ||
specify { expect(address.country).to eq("CH") } | ||
specify { expect(address.structured?).to eq(false) } | ||
specify { expect(address.street_name).to eq("") } | ||
end | ||
|
||
context "with structured address" do | ||
let(:camt) { CamtParser::File.parse('spec/fixtures/053/valid_example_v4.xml') } | ||
let(:ex_entry) { entries[6] } | ||
let(:ex_transaction) { transactions[1] } | ||
let(:entity) { ex_transaction.debitor } | ||
let(:address) { entity.postal_address } | ||
|
||
specify { expect(entity.name).to eq("Rutschmann Pia") } | ||
specify { expect(address.structured?).to eq(true) } | ||
specify { expect(address.street_name).to eq("Marktgasse") } | ||
specify { expect(address.building_number).to eq("28") } | ||
specify { expect(address.postal_code).to eq("9400") } | ||
specify { expect(address.town_name).to eq("Rorschach") } | ||
specify { expect(address.country).to eq("CH") } | ||
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