Skip to content

Commit

Permalink
Merge pull request #5 from hoelzle/fix/s-type-address-line
Browse files Browse the repository at this point in the history
fix: drawing structured addresses
  • Loading branch information
mitosch authored Sep 11, 2024
2 parents c8424f9 + e8a3e70 commit 9d14016
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 7 deletions.
9 changes: 6 additions & 3 deletions lib/prawn/swiss_qr_bill/sections/section.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,13 @@ def line_spacing
def build_address(address)
[
address[:name],
address[:line1],
address[:line2],
if address[:type] == 'S'
[address[:line1], address[:line2]].compact.join(' ')
else
[address[:line1], address[:line2]]
end,
[address[:postal_code], address[:city]].compact.join(' ')
].compact.join("\n")
].flatten.compact.join("\n")
end

def load_specs
Expand Down
28 changes: 28 additions & 0 deletions spec/prawn/swiss_qr_bill/bill_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,33 @@
it 'can be drawn through prawn' do
document.swiss_qr_bill(bill_full)
end

context 'with structured address (address type S)' do
let(:s_type_address) { DataManager.build_bill(:s_type_address) }

it 'combines `line1` (street name) and `line2` (street number) on a single line' do
described_class.new(document, s_type_address).draw

pdf_text = PDF::Reader.new(StringIO.new(document.render)).page(1).text

expect(pdf_text).to include('Schybenächerweg 553')
.and include('Musterstrasse 1')
end
end

context 'with unstructured address (address type K)' do
let(:k_type_address) { DataManager.build_bill(:k_type_address) }

it 'draws `line1` (street name + number ) and `line2` (postal_code + city) on separate lines' do
described_class.new(document, k_type_address).draw

pdf_text = PDF::Reader.new(StringIO.new(document.render)).page(1).text

expect(pdf_text).to include("Musterstrasse 123\n")
.and include("8000 Seldwyla\n")
.and include("Simonstrasse 1\n")
.and include("5000 Aarau\n")
end
end
end
end
48 changes: 44 additions & 4 deletions spec/support/bill_data.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ bill_data:
address:
type: S
name: Mischa Schindowski
line1: Schybenächerweg 553
line1: Schybenächerweg
line2: 553
postal_code: 5324
city: Full-Reuenthal
country: CH
debtor:
address:
type: S
name: Simon Muster
line1: Musterstrasse 1
line1: Musterstrasse
line2: 1
postal_code: 8000
city: Zürich
country: CH
Expand Down Expand Up @@ -111,15 +113,17 @@ bill_data:
address:
type: S
name: Mischa Schindowski
line1: Schybenächerweg 553
line1: Schybenächerweg
line2: 553
postal_code: 5324
city: Full-Reuenthal
country: CH
debtor:
address:
type: S
name: Simon Muster
line1: Musterstrasse 1
line1: Musterstrasse
line2: 1
postal_code: 8000
city: Zürich
country: CH
Expand Down Expand Up @@ -202,3 +206,39 @@ bill_data:
currency: CHF
reference: RF18 5390 0754 7034
reference_type: SCOR
s_type_address:
creditor:
iban: CH58 0079 1123 0008 8901 2
address:
type: S
name: Mischa Schindowski
line1: Schybenächerweg
line2: 553
postal_code: 5324
city: Full-Reuenthal
country: CH
debtor:
address:
type: S
name: Simon Muster
line1: Musterstrasse
line2: 1
postal_code: 8000
city: Zürich
country: CH
k_type_address:
creditor:
iban: CH58 0079 1123 0008 8901 2
address:
type: K
name: Max Muster & Söhne
line1: Musterstrasse 123
line2: 8000 Seldwyla
country: CH
debtor:
address:
type: K
name: Simon Muster
line1: Simonstrasse 1
line2: 5000 Aarau
country: CH

0 comments on commit 9d14016

Please sign in to comment.