invoice_printer 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,6 +11,7 @@ class DatesBoxTest < Minitest::Test
11
11
  invoice = InvoicePrinter::Document.new(params)
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:')
15
16
  assert_equal true, pdf_analysis.strings.include?('Due date:')
16
17
  end
@@ -23,6 +24,7 @@ class DatesBoxTest < Minitest::Test
23
24
  invoice = InvoicePrinter::Document.new(params)
24
25
  rendered_pdf = InvoicePrinter.render(document: invoice)
25
26
  pdf_analysis = PDF::Inspector::Text.analyze(rendered_pdf)
27
+
26
28
  assert_equal true, pdf_analysis.strings.include?('Issue date:')
27
29
  assert_equal false, pdf_analysis.strings.include?('Due date:')
28
30
  end
@@ -35,6 +37,7 @@ class DatesBoxTest < Minitest::Test
35
37
  invoice = InvoicePrinter::Document.new(params)
36
38
  rendered_pdf = InvoicePrinter.render(document: invoice)
37
39
  pdf_analysis = PDF::Inspector::Text.analyze(rendered_pdf)
40
+
38
41
  assert_equal false, pdf_analysis.strings.include?('Issue date:')
39
42
  assert_equal true, pdf_analysis.strings.include?('Due date:')
40
43
  end
@@ -47,6 +50,7 @@ class DatesBoxTest < Minitest::Test
47
50
  invoice = InvoicePrinter::Document.new(params)
48
51
  rendered_pdf = InvoicePrinter.render(document: invoice)
49
52
  pdf_analysis = PDF::Inspector::Text.analyze(rendered_pdf)
53
+
50
54
  assert_equal false, pdf_analysis.strings.include?('Issue date:')
51
55
  assert_equal false, pdf_analysis.strings.include?('Due date:')
52
56
  end
@@ -7,8 +7,8 @@ class InvoicePrinterTest < Minitest::Test
7
7
  invoice = InvoicePrinter::Document.new(default_document_params)
8
8
  rendered_pdf = InvoicePrinter.render(document: invoice)
9
9
  pdf_analysis = PDF::Inspector::Text.analyze(rendered_pdf)
10
-
11
10
  strings = InvoicePrinter::PDFDocument.new(document: invoice).to_a
11
+
12
12
  assert_equal strings, pdf_analysis.strings
13
13
  end
14
14
  end
@@ -19,11 +19,9 @@ class ItemsTableTest < Minitest::Test
19
19
  test_ommiting_column(column: 'price', label: :price_per_item)
20
20
  end
21
21
 
22
- # TODO: We need to distinguish between items' taxes and document taxes
23
- #
24
- #def test_omitting_tax_column
25
- # test_ommiting_column(column: 'tax', label: :tax)
26
- #end
22
+ def test_omitting_tax_column
23
+ test_ommiting_column(column: 'tax', label: :tax)
24
+ end
27
25
 
28
26
  def test_omitting_amount_column
29
27
  test_ommiting_column(column: 'amount', label: :amount)
data/test/labels_test.rb CHANGED
@@ -6,7 +6,6 @@ class LabelsTest < Minitest::Test
6
6
  def test_setting_global_labels
7
7
  labels = { provider: 'Default Provider', purchaser: 'Default Purchaser' }
8
8
  InvoicePrinter.labels = labels
9
-
10
9
  invoice = InvoicePrinter::Document.new(default_document_params)
11
10
  rendered_pdf = InvoicePrinter.render(document: invoice)
12
11
  pdf_analysis = PDF::Inspector::Text.analyze(rendered_pdf)
@@ -17,7 +16,6 @@ class LabelsTest < Minitest::Test
17
16
 
18
17
  def test_setting_instant_labels
19
18
  labels = { provider: 'Current Provider', purchaser: 'Current Purchaser' }
20
-
21
19
  invoice = InvoicePrinter::Document.new(default_document_params)
22
20
  rendered_pdf = InvoicePrinter.render(document: invoice, labels: labels)
23
21
  pdf_analysis = PDF::Inspector::Text.analyze(rendered_pdf)
data/test/test_ext.rb CHANGED
@@ -1,13 +1,28 @@
1
+ # Requiring this file extends the original PDFDocument class with +to_a+ method
2
+ # returning the strings representation of the class.
3
+
1
4
  module InvoicePrinter
2
5
  class PDFDocument
3
6
  # Expose the document as an array of attributes in order as their
4
7
  # appear on PDF
5
8
  def to_a
6
9
  strings = []
7
-
8
10
  strings << @labels[:name]
9
11
  strings << @document.number
12
+ strings << provider_box
13
+ strings << purchaser_box
14
+ strings << account_box
15
+ strings << dates_box
16
+ strings << items_table
17
+ strings << totals_table
18
+ strings.flatten.reject(&:empty?)
19
+ end
10
20
 
21
+ private
22
+
23
+ # Strings representaion of provider's box
24
+ def provider_box
25
+ strings = []
11
26
  strings << @labels[:provider]
12
27
  strings << @document.provider_name
13
28
  strings << "#{@document.provider_street} #{@document.provider_street_number}".strip
@@ -15,10 +30,16 @@ module InvoicePrinter
15
30
  strings << @document.provider_city
16
31
  strings << @document.provider_city_part
17
32
  strings << @document.provider_extra_address_line
33
+ strings << "#{@labels[:ic]}: #{@document.provider_ic}" \
34
+ unless @document.provider_ic.empty?
35
+ strings << "#{@labels[:dic]}: #{@document.provider_dic}" \
36
+ unless @document.provider_dic.empty?
37
+ strings
38
+ end
18
39
 
19
- strings << "#{@labels[:ic]}: #{@document.provider_ic}" unless @document.provider_ic.empty?
20
- strings << "#{@labels[:dic]}: #{@document.provider_dic}" unless @document.provider_dic.empty?
21
-
40
+ # Strings representaion of purchaser's box
41
+ def purchaser_box
42
+ strings = []
22
43
  strings << @labels[:purchaser]
23
44
  strings << @document.purchaser_name
24
45
  strings << "#{@document.purchaser_street} #{@document.purchaser_street_number}".strip
@@ -26,31 +47,43 @@ module InvoicePrinter
26
47
  strings << @document.purchaser_city
27
48
  strings << @document.purchaser_city_part
28
49
  strings << @document.purchaser_extra_address_line
50
+ strings << "#{@labels[:ic]}: #{@document.purchaser_ic}" \
51
+ unless @document.purchaser_ic.empty?
52
+ strings << "#{@labels[:dic]}: #{@document.purchaser_dic}" \
53
+ unless @document.purchaser_dic.empty?
54
+ strings
55
+ end
29
56
 
30
- strings << "#{@labels[:ic]}: #{@document.purchaser_ic}" unless @document.purchaser_ic.empty?
31
- strings << "#{@labels[:dic]}: #{@document.purchaser_dic}" unless @document.purchaser_dic.empty?
32
-
33
- # Account
57
+ # Strings representaion of account's box
58
+ def account_box
59
+ strings = []
34
60
  if @document.bank_account_number.nil?
35
61
  strings << @labels[:payment_in_cash]
36
62
  else
37
63
  strings << @labels[:payment_by_transfer]
38
64
  end
39
-
40
65
  strings << "#{@labels[:account_number]}:"
41
66
  strings << @document.bank_account_number
42
67
  strings << "#{@labels[:swift]}:"
43
68
  strings << @document.account_swift
44
69
  strings << "#{@labels[:iban]}:"
45
70
  strings << @document.account_iban
71
+ strings
72
+ end
46
73
 
47
- # Dates
74
+ # Strings representaion of dates box
75
+ def dates_box
76
+ strings = []
48
77
  strings << "#{@labels[:issue_date]}:"
49
78
  strings << @document.issue_date
50
79
  strings << "#{@labels[:due_date]}:"
51
80
  strings << @document.due_date
81
+ strings
82
+ end
52
83
 
53
- # Items table
84
+ # Strings representaion of items table
85
+ def items_table
86
+ strings = []
54
87
  strings << @labels[:item] if determine_items_structure[:names]
55
88
  strings << @labels[:quantity] if determine_items_structure[:quantities]
56
89
  strings << @labels[:unit] if determine_items_structure[:units]
@@ -58,8 +91,12 @@ module InvoicePrinter
58
91
  strings << @labels[:tax] if determine_items_structure[:taxes]
59
92
  strings << @labels[:amount] if determine_items_structure[:amounts]
60
93
  strings << items_to_a(@document.items)
94
+ strings
95
+ end
61
96
 
62
- # Total table
97
+ # Strings representaion of totals table
98
+ def totals_table
99
+ strings = []
63
100
  strings << "#{@labels[:subtotal]}:"
64
101
  strings << @document.subtotal
65
102
  strings << "#{@labels[:tax]}:"
@@ -68,17 +105,11 @@ module InvoicePrinter
68
105
  strings << @document.tax2
69
106
  strings << "#{@labels[:tax3]}:"
70
107
  strings << @document.tax3
71
-
72
108
  strings << "#{@labels[:total]}: #{@document.total}"
73
-
74
- # TODO: dynamically test page numbers
75
- strings << '1 / 1'
76
-
77
- strings.flatten.reject(&:empty?)
109
+ strings
78
110
  end
79
111
 
80
- private
81
-
112
+ # Convert document +items+ to a single string array
82
113
  def items_to_a(items)
83
114
  ary = []
84
115
  items.each do |item|
@@ -87,6 +118,7 @@ module InvoicePrinter
87
118
  ary.flatten
88
119
  end
89
120
 
121
+ # Convert document +item+ to a single string array
90
122
  def item_to_a(item)
91
123
  ary = []
92
124
  ary << item.name
data/test/test_helper.rb CHANGED
@@ -3,7 +3,7 @@ require 'invoice_printer'
3
3
  require 'test_ext'
4
4
  require 'minitest/autorun'
5
5
 
6
- # Helpers for easy-to-build documents
6
+ # Test helpers
7
7
  module InvoicePrinterHelpers
8
8
  def default_document_params
9
9
  {
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.2
4
+ version: 0.0.3
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-04-12 00:00:00.000000000 Z
11
+ date: 2016-06-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prawn
@@ -78,6 +78,7 @@ files:
78
78
  - LICENSE.txt
79
79
  - README.md
80
80
  - Rakefile
81
+ - examples/czech_invoice.jpg
81
82
  - examples/czech_invoice.pdf
82
83
  - examples/czech_invoice.rb
83
84
  - examples/example.jpg