diff --git a/lib/prawn/swiss_qr_bill/sections/section.rb b/lib/prawn/swiss_qr_bill/sections/section.rb index eafac72..efccc32 100644 --- a/lib/prawn/swiss_qr_bill/sections/section.rb +++ b/lib/prawn/swiss_qr_bill/sections/section.rb @@ -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 diff --git a/spec/prawn/swiss_qr_bill/bill_spec.rb b/spec/prawn/swiss_qr_bill/bill_spec.rb index 3598c7e..3ccc26d 100644 --- a/spec/prawn/swiss_qr_bill/bill_spec.rb +++ b/spec/prawn/swiss_qr_bill/bill_spec.rb @@ -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 diff --git a/spec/support/bill_data.yml b/spec/support/bill_data.yml index 26bcdd8..db5a39f 100644 --- a/spec/support/bill_data.yml +++ b/spec/support/bill_data.yml @@ -5,7 +5,8 @@ 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 @@ -13,7 +14,8 @@ bill_data: address: type: S name: Simon Muster - line1: Musterstrasse 1 + line1: Musterstrasse + line2: 1 postal_code: 8000 city: Zürich country: CH @@ -111,7 +113,8 @@ 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 @@ -119,7 +122,8 @@ bill_data: address: type: S name: Simon Muster - line1: Musterstrasse 1 + line1: Musterstrasse + line2: 1 postal_code: 8000 city: Zürich country: CH @@ -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