bollettino 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +5 -5
  2. data/.rubocop.yml +103 -0
  3. data/.travis.yml +3 -3
  4. data/CHANGELOG.md +31 -3
  5. data/README.md +8 -8
  6. data/bollettino.gemspec +10 -7
  7. data/lib/bollettino.rb +15 -12
  8. data/lib/bollettino/generator.rb +24 -20
  9. data/lib/bollettino/model/address.rb +22 -0
  10. data/lib/bollettino/model/base.rb +9 -0
  11. data/lib/bollettino/model/payee.rb +21 -0
  12. data/lib/bollettino/model/payer.rb +20 -0
  13. data/lib/bollettino/model/payment_order.rb +24 -0
  14. data/lib/bollettino/model/slip.rb +25 -0
  15. data/lib/bollettino/renderer/address.rb +32 -0
  16. data/lib/bollettino/renderer/base.rb +46 -0
  17. data/lib/bollettino/renderer/errors.rb +14 -0
  18. data/lib/bollettino/renderer/payee.rb +34 -0
  19. data/lib/bollettino/renderer/payer.rb +28 -0
  20. data/lib/bollettino/renderer/payment_order.rb +45 -0
  21. data/lib/bollettino/renderer/slip.rb +29 -0
  22. data/lib/bollettino/version.rb +3 -1
  23. data/spec/integration/generation_spec.rb +8 -9
  24. data/spec/spec_helper.rb +9 -1
  25. data/spec/unit/bollettino/generator_spec.rb +8 -35
  26. data/spec/unit/bollettino/model/address_spec.rb +20 -0
  27. data/spec/unit/bollettino/model/payee_spec.rb +18 -0
  28. data/spec/unit/bollettino/model/payer_spec.rb +24 -0
  29. data/spec/unit/bollettino/model/payment_order_spec.rb +19 -0
  30. data/spec/unit/bollettino/model/slip_spec.rb +29 -0
  31. data/spec/unit/bollettino/renderer/address_spec.rb +28 -0
  32. data/spec/unit/bollettino/renderer/payee_spec.rb +39 -0
  33. data/spec/unit/bollettino/renderer/payer_spec.rb +41 -0
  34. data/spec/unit/bollettino/renderer/payment_order_spec.rb +40 -0
  35. data/spec/unit/bollettino/renderer/slip_spec.rb +54 -0
  36. metadata +81 -51
  37. data/lib/bollettino/models/address.rb +0 -18
  38. data/lib/bollettino/models/payee.rb +0 -17
  39. data/lib/bollettino/models/payer.rb +0 -16
  40. data/lib/bollettino/models/payment_order.rb +0 -20
  41. data/lib/bollettino/models/slip.rb +0 -21
  42. data/lib/bollettino/renderer.rb +0 -47
  43. data/lib/bollettino/renderers/address_renderer.rb +0 -24
  44. data/lib/bollettino/renderers/payee_renderer.rb +0 -26
  45. data/lib/bollettino/renderers/payer_renderer.rb +0 -20
  46. data/lib/bollettino/renderers/payment_order_renderer.rb +0 -37
  47. data/lib/bollettino/renderers/slip_renderer.rb +0 -21
  48. data/spec/unit/bollettino/models/address_spec.rb +0 -12
  49. data/spec/unit/bollettino/models/payee_spec.rb +0 -10
  50. data/spec/unit/bollettino/models/payer_spec.rb +0 -12
  51. data/spec/unit/bollettino/models/payment_order_spec.rb +0 -11
  52. data/spec/unit/bollettino/models/slip_spec.rb +0 -15
  53. data/spec/unit/bollettino/renderers/address_renderer_spec.rb +0 -23
  54. data/spec/unit/bollettino/renderers/payee_renderer_spec.rb +0 -37
  55. data/spec/unit/bollettino/renderers/payer_renderer_spec.rb +0 -27
  56. data/spec/unit/bollettino/renderers/payment_order_renderer_spec.rb +0 -39
  57. data/spec/unit/bollettino/renderers/slip_renderer_spec.rb +0 -34
@@ -1,18 +0,0 @@
1
- # Address
2
- #
3
- # @author Alessandro Desatnis <desa.alessandro@gmail.com>
4
- class Bollettino::Address
5
- include Virtus.model
6
-
7
- # !@attribute [rw] street
8
- # @return [String] the address street
9
- attribute :street, String
10
-
11
- # !@attribute [rw] zip
12
- # @return [String] the address ZIP
13
- attribute :zip, String
14
-
15
- # !@attribute [rw] location
16
- # @return [String] the address location (city, state etc.)
17
- attribute :location, String
18
- end
@@ -1,17 +0,0 @@
1
- # Payee
2
- #
3
- # The payee is the party requesting payment. A payee is associated with a
4
- # postal account.
5
- #
6
- # @author Alessandro Desatnis <desa.alessandro@gmail.com>
7
- class Bollettino::Payee
8
- include Virtus.model
9
-
10
- # !@attribute [rw] account_number
11
- # @return [String] the postal account's number
12
- attribute :account_number, String
13
-
14
- # !@attribute [rw] name
15
- # @return [String] the account holder's name
16
- attribute :name, String
17
- end
@@ -1,16 +0,0 @@
1
- # Payer
2
- #
3
- # The payer is the party making the payment.
4
- #
5
- # @author Alessandro Desatnis <desa.alessandro@gmail.com>
6
- class Bollettino::Payer
7
- include Virtus.model
8
-
9
- # !@attribute [rw] name
10
- # @return [String] the payer's full name
11
- attribute :name, String
12
-
13
- # !@attribute [rw] address
14
- # @return [Bollettino::Address] the payer's address
15
- attribute :address, Bollettino::Address
16
- end
@@ -1,20 +0,0 @@
1
- # Payment order
2
- #
3
- # A payment order is a request for payment from the payee to the payer.
4
- #
5
- # @author Alessandro Desatnis <desa.alessandro@gmail.com>
6
- class Bollettino::PaymentOrder
7
- include Virtus.model
8
-
9
- # !@attribute [rw] numeric amount
10
- # @return [Float] the payment's amount
11
- attribute :numeric_amount, Float
12
-
13
- # !@attribute [rw] text amount
14
- # @return [String] the payment's amount in letters
15
- attribute :text_amount, String
16
-
17
- # !@attribute [rw] reason
18
- # @return [String] the reason for the payment
19
- attribute :reason, String
20
- end
@@ -1,21 +0,0 @@
1
- # Slip
2
- #
3
- # A slip is just the composition of a Payee, a Payer and a PaymentOrder. It is
4
- # passed to {#Bollettino::Generator} to create the final image.
5
- #
6
- # @author Alessandro Desatnis <desa.alessandro@gmail.com>
7
- class Bollettino::Slip
8
- include Virtus.model
9
-
10
- # !@attribute [rw] payee
11
- # @return [Bollettino::Payee] the payee
12
- attribute :payee, Bollettino::Payee
13
-
14
- # !@attribute [rw] payer
15
- # @return [Bollettino::Payer] the payer
16
- attribute :payer, Bollettino::Payer
17
-
18
- # !@attribute [rw] payment order
19
- # @return [Bollettino::PaymentOrder] the payment order
20
- attribute :payment_order, Bollettino::PaymentOrder
21
- end
@@ -1,47 +0,0 @@
1
- # Base rebder
2
- #
3
- # @abstract Subclass and override {.render} to create a renderer
4
- #
5
- # @author Alessandro Desantis <desa.alessandro@gmail.com>
6
- class Bollettino::Renderer
7
- KERNING_NORMAL = 1
8
-
9
- KERNING_BOX = 17.5
10
- KERNING_BOX_SMALLER = 17
11
- KERNING_BOX_SMALLEST = 16
12
-
13
- FONT_SIZE_NORMAL = 30
14
- FONT_SIZE_SMALL = 25
15
-
16
- # Renders the given model on the image.
17
- #
18
- # @param image [MiniMagick::Image]
19
- # @param model
20
- #
21
- # @abstract This method must be overridden by the renderers
22
- def self.render(image, model)
23
- raise NotImplementedError
24
- end
25
-
26
- protected
27
-
28
- def self.write_text(image, coords, text, kerning = KERNING_NORMAL, font_size = FONT_SIZE_NORMAL)
29
- image.combine_options do |c|
30
- c.font 'courier'
31
- c.fill 'black'
32
- c.pointsize font_size
33
- c.gravity 'southwest'
34
- c.kerning kerning
35
- c.draw %Q[text #{coords.join(',')} "#{text.to_s.upcase.gsub('"', '\"')}"]
36
- end
37
- end
38
-
39
- # Rendering error
40
- #
41
- # This error is usually raised when some data can't be renderered because
42
- # it's malformed.
43
- #
44
- # @author Alessandro Desantis <desa.alessandro@gmail.com>
45
- class RenderingError < StandardError
46
- end
47
- end
@@ -1,24 +0,0 @@
1
- class Bollettino::Renderer::AddressRenderer < Bollettino::Renderer
2
- def self.render(image, address)
3
- render_street(image, address)
4
- render_zip(image, address)
5
- render_location(image, address)
6
- end
7
-
8
- private
9
-
10
- def self.render_street(image, address)
11
- write_text(image, [85, 267], address.street[0..29], KERNING_NORMAL, FONT_SIZE_SMALL)
12
- write_text(image, [1508, 267], address.street[0..22], KERNING_BOX_SMALLEST)
13
- end
14
-
15
- def self.render_zip(image, address)
16
- write_text(image, [85, 223], address.zip[0..29], KERNING_NORMAL, FONT_SIZE_SMALL)
17
- write_text(image, [1508, 200], address.zip[0..4], KERNING_BOX_SMALLEST)
18
- end
19
-
20
- def self.render_location(image, address)
21
- write_text(image, [85, 180], address.location[0..29], KERNING_NORMAL, FONT_SIZE_SMALL)
22
- write_text(image, [1713, 200], address.location[0..16], KERNING_BOX_SMALLEST)
23
- end
24
- end
@@ -1,26 +0,0 @@
1
- class Bollettino::Renderer::PayeeRenderer < Bollettino::Renderer
2
- def self.render(image, payee)
3
- render_account_number(image, payee)
4
- render_name(image, payee)
5
- end
6
-
7
- private
8
-
9
- def self.render_account_number(image, payee)
10
- if payee.account_number.length > 10
11
- raise RenderingError, "Account number can't be longer than 10 characters"
12
- end
13
-
14
- [[265, 695], [1310, 695]].each do |coords|
15
- write_text(image, coords, payee.account_number, KERNING_BOX)
16
- end
17
- end
18
-
19
- def self.render_name(image, payee)
20
- write_text(image, [90, 585], payee.name[0..46])
21
- write_text(image, [90, 545], payee.name[47..93])
22
-
23
- write_text(image, [1105, 590], payee.name[0..33], KERNING_BOX_SMALLER)
24
- write_text(image, [1105, 545], payee.name[34..67], KERNING_BOX_SMALLER)
25
- end
26
- end
@@ -1,20 +0,0 @@
1
- class Bollettino::Renderer::PayerRenderer < Bollettino::Renderer
2
- def self.render(image, payer)
3
- render_name(image, payer)
4
- render_address(image, payer)
5
- end
6
-
7
- private
8
-
9
- def self.render_name(image, payer)
10
- write_text(image, [85, 360], payer.name[0..24])
11
- write_text(image, [85, 315], payer.name[25..49])
12
-
13
- write_text(image, [1508, 375], payer.name[0..22], KERNING_BOX_SMALLEST)
14
- write_text(image, [1508, 330], payer.name[23..45], KERNING_BOX_SMALLEST)
15
- end
16
-
17
- def self.render_address(image, payer)
18
- Bollettino::Renderer::AddressRenderer.render(image, payer.address)
19
- end
20
- end
@@ -1,37 +0,0 @@
1
- class Bollettino::Renderer::PaymentOrderRenderer < Bollettino::Renderer
2
- def self.render(image, payment_order)
3
- render_numeric_amount(image, payment_order)
4
- render_text_amount(image, payment_order)
5
- render_reason(image, payment_order)
6
- end
7
-
8
- private
9
-
10
- def self.render_numeric_amount(image, payment_order)
11
- numeric_amount = payment_order.numeric_amount
12
- numeric_amount = ('%.2f' % numeric_amount).to_s.gsub('.', '')
13
-
14
- if numeric_amount.length > 7
15
- raise RenderingError, "Numeric amount can't be longer than 7 total digits"
16
- end
17
-
18
- numeric_amount_x = 1000 - 35 * numeric_amount.length.to_i
19
-
20
- [[numeric_amount_x, 690], [numeric_amount_x + 1315, 690]].each do |coords|
21
- write_text(image, coords, numeric_amount, KERNING_BOX)
22
- end
23
- end
24
-
25
- def self.render_reason(image, payment_order)
26
- write_text(image, [90, 475], payment_order.reason[0..46])
27
- write_text(image, [90, 435], payment_order.reason[47..93])
28
-
29
- write_text(image, [1110, 475], payment_order.reason[0..60])
30
- write_text(image, [1110, 435], payment_order.reason[61..121])
31
- end
32
-
33
- def self.render_text_amount(image, payment_order)
34
- write_text(image, [245, 650], payment_order.text_amount[0..38])
35
- write_text(image, [1435, 650], payment_order.text_amount[0..44])
36
- end
37
- end
@@ -1,21 +0,0 @@
1
- class Bollettino::Renderer::SlipRenderer < Bollettino::Renderer
2
- def self.render(image, slip)
3
- render_payment_order(image, slip)
4
- render_payee(image, slip)
5
- render_payer(image, slip)
6
- end
7
-
8
- private
9
-
10
- def self.render_payment_order(image, slip)
11
- Bollettino::Renderer::PaymentOrderRenderer.render(image, slip.payment_order)
12
- end
13
-
14
- def self.render_payee(image, slip)
15
- Bollettino::Renderer::PayeeRenderer.render(image, slip.payee)
16
- end
17
-
18
- def self.render_payer(image, slip)
19
- Bollettino::Renderer::PayerRenderer.render(image, slip.payer)
20
- end
21
- end
@@ -1,12 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Bollettino::Address do
4
- it 'is instantiated correctly' do
5
- described_class.new(
6
- street: '3681 Foggy Moor',
7
- zip: '19147-0834',
8
- city: 'Grayson',
9
- state: 'Pennsylvania'
10
- )
11
- end
12
- end
@@ -1,10 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Bollettino::Payee do
4
- it 'is instantiated correctly' do
5
- described_class.new(
6
- account_number: '0123456789',
7
- name: 'Acme Inc.'
8
- )
9
- end
10
- end
@@ -1,12 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Bollettino::Payer do
4
- it 'is instantiated correctly' do
5
- address = Bollettino::Address.new
6
-
7
- described_class.new(
8
- name: 'John Doe',
9
- address: address
10
- )
11
- end
12
- end
@@ -1,11 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Bollettino::Payee do
4
- it 'is instantiated correctly' do
5
- described_class.new(
6
- numeric_amount: 54.31,
7
- text_amount: 'Cinquantaquattro/31',
8
- reason: 'Invoice INV-1391'
9
- )
10
- end
11
- end
@@ -1,15 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Bollettino::Slip do
4
- it 'is instantiated correctly' do
5
- payee = Bollettino::Payee.new
6
- payer = Bollettino::Payer.new
7
- payment_order = Bollettino::PaymentOrder.new
8
-
9
- described_class.new(
10
- payee: payee,
11
- payer: payer,
12
- payment_order: payment_order
13
- )
14
- end
15
- end
@@ -1,23 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Bollettino::Renderer::AddressRenderer do
4
- subject { described_class }
5
-
6
- describe '.render' do
7
- it 'renders the address' do
8
- address = stub(
9
- street: 'Via Fasulla, 123',
10
- location: 'Roma',
11
- zip: '00100'
12
- )
13
-
14
- image = stub()
15
-
16
- subject
17
- .expects(:write_text)
18
- .times(6)
19
-
20
- subject.render image, address
21
- end
22
- end
23
- end
@@ -1,37 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Bollettino::Renderer::PayeeRenderer do
4
- subject { described_class }
5
-
6
- describe '.render' do
7
- it 'renders the payee' do
8
- payee = stub(
9
- account_number: '0123456789',
10
- name: 'Acme Inc.'
11
- )
12
-
13
- image = stub()
14
-
15
- subject
16
- .expects(:write_text)
17
- .times(6)
18
-
19
- subject.render image, payee
20
- end
21
-
22
- context 'when account_number is longer than 10 characters' do
23
- it 'raises an error' do
24
- payee = stub(
25
- account_number: '01234567891',
26
- name: 'Acme Inc.'
27
- )
28
-
29
- image = stub()
30
-
31
- expect {
32
- subject.render image, payee
33
- }.to raise_error(Bollettino::Renderer::RenderingError)
34
- end
35
- end
36
- end
37
- end
@@ -1,27 +0,0 @@
1
- require 'spec_helper'
2
-
3
- RSpec.describe Bollettino::Renderer::PayerRenderer do
4
- subject { described_class }
5
-
6
- describe '.render' do
7
- it 'renders the payer' do
8
- payer = stub(
9
- name: 'Acme Inc.',
10
- address: stub()
11
- )
12
-
13
- image = stub()
14
-
15
- Bollettino::Renderer::AddressRenderer
16
- .expects(:render)
17
- .with(image, payer.address)
18
- .once
19
-
20
- subject
21
- .expects(:write_text)
22
- .times(4)
23
-
24
- subject.render image, payer
25
- end
26
- end
27
- end