invoice_printer 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -38,6 +38,14 @@ module InvoicePrinter
38
38
  # price_per_item: 'Price per item',
39
39
  # amount: 'Amount'
40
40
  # }
41
+ #
42
+ # You can denote the details or translations of labels by using sublabels.
43
+ # To set a sublabel for a label, just assign it under +sublabels+ e.g.
44
+ #
45
+ # InvoicePrinter.labels = {
46
+ # ...
47
+ # sublabels: { tax: 'Daň', amount: 'Celkem' }
48
+ # }
41
49
  def self.labels=(labels)
42
50
  PDFDocument.labels = labels
43
51
  end
@@ -8,7 +8,7 @@ class BackgroundTest < Minitest::Test
8
8
  end
9
9
 
10
10
  def test_background_render
11
- InvoicePrinter.render(document: @invoice, background: './examples/background.jpg')
11
+ InvoicePrinter.render(document: @invoice, background: './examples/background.png')
12
12
  InvoicePrinter.render(document: @invoice, background: nil)
13
13
  InvoicePrinter.render(document: @invoice)
14
14
  end
@@ -12,8 +12,8 @@ class DatesBoxTest < Minitest::Test
12
12
  rendered_pdf = InvoicePrinter.render(document: invoice)
13
13
  pdf_analysis = PDF::Inspector::Text.analyze(rendered_pdf)
14
14
 
15
- assert_equal true, pdf_analysis.strings.include?('Issue date:')
16
- assert_equal true, pdf_analysis.strings.include?('Due date:')
15
+ assert_equal true, pdf_analysis.strings.include?('Issue date')
16
+ assert_equal true, pdf_analysis.strings.include?('Due date')
17
17
  end
18
18
 
19
19
  def test_setting_only_issue_date
@@ -25,8 +25,8 @@ class DatesBoxTest < Minitest::Test
25
25
  rendered_pdf = InvoicePrinter.render(document: invoice)
26
26
  pdf_analysis = PDF::Inspector::Text.analyze(rendered_pdf)
27
27
 
28
- assert_equal true, pdf_analysis.strings.include?('Issue date:')
29
- assert_equal false, pdf_analysis.strings.include?('Due date:')
28
+ assert_equal true, pdf_analysis.strings.include?('Issue date')
29
+ assert_equal false, pdf_analysis.strings.include?('Due date')
30
30
  end
31
31
 
32
32
  def test_setting_only_due_date
@@ -38,8 +38,8 @@ class DatesBoxTest < Minitest::Test
38
38
  rendered_pdf = InvoicePrinter.render(document: invoice)
39
39
  pdf_analysis = PDF::Inspector::Text.analyze(rendered_pdf)
40
40
 
41
- assert_equal false, pdf_analysis.strings.include?('Issue date:')
42
- assert_equal true, pdf_analysis.strings.include?('Due date:')
41
+ assert_equal false, pdf_analysis.strings.include?('Issue date')
42
+ assert_equal true, pdf_analysis.strings.include?('Due date')
43
43
  end
44
44
 
45
45
  def test_setting_no_dates
@@ -51,7 +51,7 @@ class DatesBoxTest < Minitest::Test
51
51
  rendered_pdf = InvoicePrinter.render(document: invoice)
52
52
  pdf_analysis = PDF::Inspector::Text.analyze(rendered_pdf)
53
53
 
54
- assert_equal false, pdf_analysis.strings.include?('Issue date:')
55
- assert_equal false, pdf_analysis.strings.include?('Due date:')
54
+ assert_equal false, pdf_analysis.strings.include?('Issue date')
55
+ assert_equal false, pdf_analysis.strings.include?('Due date')
56
56
  end
57
57
  end
@@ -0,0 +1,33 @@
1
+ require 'test_helper'
2
+
3
+ # Integration tests running the examples from /examples directory
4
+ class ExamplesTest < Minitest::Test
5
+ def setup
6
+ examples_directory = File.expand_path('../../examples', __FILE__)
7
+ @examples = Dir.glob("#{examples_directory}/*.rb")
8
+ @test_dir = File.absolute_path('./tmp/invoice_printer_examples')
9
+ FileUtils.copy_entry examples_directory, @test_dir
10
+ end
11
+
12
+ def teardown
13
+ FileUtils.rm_rf @test_dir if File.exists?(@test_dir)
14
+ end
15
+
16
+ # 1, copy example to the test directory
17
+ # 2, run the example
18
+ # 3, compare the output with example from /examples
19
+ def test_examples
20
+ @examples.each do |example|
21
+ example_file = File.join(@test_dir, File.basename(example))
22
+ original_pdf = example.gsub('.rb', '.pdf')
23
+ result_pdf = example_file.gsub('.rb', '.pdf')
24
+
25
+ Dir.chdir(@test_dir) do
26
+ `ruby -I../../lib #{example_file}`
27
+
28
+ similarity = (File.read(original_pdf) == File.read(result_pdf))
29
+ assert_equal true, similarity, "#{original_pdf} does not match #{result_pdf}"
30
+ end
31
+ end
32
+ end
33
+ end
@@ -14,8 +14,8 @@ class PaymentBoxTest < Minitest::Test
14
14
 
15
15
  assert_equal true, pdf_analysis.strings.include?('Payment in cash')
16
16
  assert_equal false, pdf_analysis.strings.include?('Payment by bank transfer on the account below:')
17
- assert_equal false, pdf_analysis.strings.include?('SWIFT:')
18
- assert_equal false, pdf_analysis.strings.include?('IBAN:')
17
+ assert_equal false, pdf_analysis.strings.include?('SWIFT')
18
+ assert_equal false, pdf_analysis.strings.include?('IBAN')
19
19
  end
20
20
 
21
21
  def test_setting_only_local_bank_account_number
@@ -31,8 +31,8 @@ class PaymentBoxTest < Minitest::Test
31
31
  assert_equal false, pdf_analysis.strings.include?('Payment in cash')
32
32
  assert_equal true, pdf_analysis.strings.include?('Payment by bank transfer on the account below:')
33
33
  assert_equal true, pdf_analysis.strings.include?('218291829/0100')
34
- assert_equal false, pdf_analysis.strings.include?('SWIFT:')
35
- assert_equal false, pdf_analysis.strings.include?('IBAN:')
34
+ assert_equal false, pdf_analysis.strings.include?('SWIFT')
35
+ assert_equal false, pdf_analysis.strings.include?('IBAN')
36
36
  end
37
37
 
38
38
  def test_setting_bank_account_number_and_iban
@@ -48,8 +48,8 @@ class PaymentBoxTest < Minitest::Test
48
48
  assert_equal false, pdf_analysis.strings.include?('Payment in cash')
49
49
  assert_equal true, pdf_analysis.strings.include?('Payment by bank transfer on the account below:')
50
50
  assert_equal true, pdf_analysis.strings.include?('218291829/0100')
51
- assert_equal false, pdf_analysis.strings.include?('SWIFT:')
52
- assert_equal true, pdf_analysis.strings.include?('IBAN:')
51
+ assert_equal false, pdf_analysis.strings.include?('SWIFT')
52
+ assert_equal true, pdf_analysis.strings.include?('IBAN')
53
53
  assert_equal true, pdf_analysis.strings.include?('SAMPLE_IBAN')
54
54
  end
55
55
 
@@ -66,9 +66,9 @@ class PaymentBoxTest < Minitest::Test
66
66
  assert_equal false, pdf_analysis.strings.include?('Payment in cash')
67
67
  assert_equal true, pdf_analysis.strings.include?('Payment by bank transfer on the account below:')
68
68
  assert_equal true, pdf_analysis.strings.include?('218291829/0100')
69
- assert_equal true, pdf_analysis.strings.include?('SWIFT:')
69
+ assert_equal true, pdf_analysis.strings.include?('SWIFT')
70
70
  assert_equal true, pdf_analysis.strings.include?('SAMPLE_SWIFT')
71
- assert_equal false, pdf_analysis.strings.include?('IBAN:')
71
+ assert_equal false, pdf_analysis.strings.include?('IBAN')
72
72
  end
73
73
 
74
74
  def test_setting_bank_account_number_iban_and_swift
@@ -84,9 +84,9 @@ class PaymentBoxTest < Minitest::Test
84
84
  assert_equal false, pdf_analysis.strings.include?('Payment in cash')
85
85
  assert_equal true, pdf_analysis.strings.include?('Payment by bank transfer on the account below:')
86
86
  assert_equal true, pdf_analysis.strings.include?('218291829/0100')
87
- assert_equal true, pdf_analysis.strings.include?('SWIFT:')
87
+ assert_equal true, pdf_analysis.strings.include?('SWIFT')
88
88
  assert_equal true, pdf_analysis.strings.include?('SAMPLE_SWIFT')
89
- assert_equal true, pdf_analysis.strings.include?('IBAN:')
89
+ assert_equal true, pdf_analysis.strings.include?('IBAN')
90
90
  assert_equal true, pdf_analysis.strings.include?('SAMPLE_IBAN')
91
91
  end
92
92
  end
data/test/test_ext.rb CHANGED
@@ -23,8 +23,8 @@ module InvoicePrinter
23
23
  # Strings representaion of provider's box
24
24
  def provider_box
25
25
  strings = []
26
- strings << @labels[:provider]
27
26
  strings << @document.provider_name
27
+ strings << @labels[:provider]
28
28
  strings << "#{@document.provider_street} #{@document.provider_street_number}".strip
29
29
  strings << @document.provider_postcode
30
30
  strings << @document.provider_city
@@ -40,8 +40,8 @@ module InvoicePrinter
40
40
  # Strings representaion of purchaser's box
41
41
  def purchaser_box
42
42
  strings = []
43
- strings << @labels[:purchaser]
44
43
  strings << @document.purchaser_name
44
+ strings << @labels[:purchaser]
45
45
  strings << "#{@document.purchaser_street} #{@document.purchaser_street_number}".strip
46
46
  strings << @document.purchaser_postcode
47
47
  strings << @document.purchaser_city
@@ -62,11 +62,11 @@ module InvoicePrinter
62
62
  else
63
63
  strings << @labels[:payment_by_transfer]
64
64
  end
65
- strings << "#{@labels[:account_number]}:"
65
+ strings << "#{@labels[:account_number]}"
66
66
  strings << @document.bank_account_number
67
- strings << "#{@labels[:swift]}:"
67
+ strings << "#{@labels[:swift]}"
68
68
  strings << @document.account_swift
69
- strings << "#{@labels[:iban]}:"
69
+ strings << "#{@labels[:iban]}"
70
70
  strings << @document.account_iban
71
71
  strings
72
72
  end
@@ -74,9 +74,9 @@ module InvoicePrinter
74
74
  # Strings representaion of dates box
75
75
  def dates_box
76
76
  strings = []
77
- strings << "#{@labels[:issue_date]}:"
77
+ strings << "#{@labels[:issue_date]}"
78
78
  strings << @document.issue_date
79
- strings << "#{@labels[:due_date]}:"
79
+ strings << "#{@labels[:due_date]}"
80
80
  strings << @document.due_date
81
81
  strings
82
82
  end
data/test/test_helper.rb CHANGED
@@ -1,4 +1,7 @@
1
1
  require 'pdf/inspector'
2
+
3
+ lib = File.expand_path('../../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
2
5
  require 'invoice_printer'
3
6
  require 'test_ext'
4
7
  require 'minitest/autorun'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: invoice_printer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josef Strzibny
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-24 00:00:00.000000000 Z
11
+ date: 2017-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -92,14 +92,14 @@ files:
92
92
  - LICENSE.txt
93
93
  - README.md
94
94
  - Rakefile
95
- - examples/background.jpg
95
+ - examples/background.png
96
96
  - examples/complex_invoice.pdf
97
97
  - examples/complex_invoice.png
98
98
  - examples/complex_invoice.rb
99
- - examples/czech_invoice.jpg
100
99
  - examples/czech_invoice.pdf
101
100
  - examples/czech_invoice.rb
102
- - examples/example.jpg
101
+ - examples/international_invoice.pdf
102
+ - examples/international_invoice.rb
103
103
  - examples/prawn.png
104
104
  - examples/simple_invoice.pdf
105
105
  - examples/simple_invoice.rb
@@ -112,6 +112,7 @@ files:
112
112
  - lib/invoice_printer/version.rb
113
113
  - test/background_test.rb
114
114
  - test/dates_box_test.rb
115
+ - test/examples_test.rb
115
116
  - test/inputs_test.rb
116
117
  - test/invoice_printer_test.rb
117
118
  - test/items_table_test.rb
@@ -141,13 +142,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
142
  version: '0'
142
143
  requirements: []
143
144
  rubyforge_project:
144
- rubygems_version: 2.4.8
145
+ rubygems_version: 2.5.1
145
146
  signing_key:
146
147
  specification_version: 4
147
148
  summary: Super simple PDF invoicing in pure Ruby
148
149
  test_files:
149
150
  - test/background_test.rb
150
151
  - test/dates_box_test.rb
152
+ - test/examples_test.rb
151
153
  - test/inputs_test.rb
152
154
  - test/invoice_printer_test.rb
153
155
  - test/items_table_test.rb
Binary file
Binary file
data/examples/example.jpg DELETED
Binary file