postino 0.0.2 → 1.0.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9588e87c9cb359ec02b8fd9f6a9549a1c8b4cc86
4
- data.tar.gz: 73bd081ec9df15a88d643f9e63d9df9d64afaf76
3
+ metadata.gz: 980470702b3fe95393d856bec98897a6d71a1d9f
4
+ data.tar.gz: 056a7e3d03ccc351acd64db10c68ff7a1bc67171
5
5
  SHA512:
6
- metadata.gz: b14318f8ce294332acfe76abf0f9dba5010567a7aedefa651076ec00b3bf79a36316f86c687a303ee37f53b3e0b77804d9d7d6d5178e90ee563eadb8bcee7114
7
- data.tar.gz: bbc992f899f2c55d4439edf3c10d71f5c6b2fc2dde2af12c558cb870561db853ad5cc7d3ae539ddb7410f569c301f8c7bcb9a8c2f4df6e1d153825a56bccc39c
6
+ metadata.gz: 0ad90cf4adbc4b6d1031aec928e072196c6d8ceb56d57b7edafcacf77180abe05c0b1c82537ec76f42104dd5391308064832f2b0522387532a90e6e92065addc
7
+ data.tar.gz: 4b8c9fb232d0ccf623647d9fffb340f3d83bf9e4fa5a2c4f3c38fb4da2dcbe2c0b7de15dad527c07dfa075ba6577e7e153fb84e9482be6c08de33a44eceff514
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ spec/**/*.pdf
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Postino [![Build Status](https://travis-ci.org/alessandro1997/postino.png?branch=master)](https://travis-ci.org/alessandro1997/postino) [![Dependency Status](https://gemnasium.com/alessandro1997/postino.png)](https://gemnasium.com/alessandro1997/postino)
1
+ # Postino [![Gem Version](https://badge.fury.io/rb/postino.png)](http://badge.fury.io/rb/postino) [![Build Status](https://travis-ci.org/alessandro1997/postino.png?branch=master)](https://travis-ci.org/alessandro1997/postino) [![Dependency Status](https://gemnasium.com/alessandro1997/postino.png)](https://gemnasium.com/alessandro1997/postino) [![Code Climate](https://codeclimate.com/github/alessandro1997/postino.png)](https://codeclimate.com/github/alessandro1997/postino)
2
2
 
3
3
  [Postino](https://github.com/alessandro1997/postino) is a Ruby gem that allows to quickly generate Italian postal
4
4
  payment forms in PDF format using [Prawn](https://github.com/prawnpdf/prawn).
@@ -20,20 +20,21 @@ Or install it yourself as:
20
20
  ## Usage
21
21
 
22
22
  ```ruby
23
- Postino::Generator.generate_form('form.pdf', {
24
- account_number: '0123456789',
25
- numeric_amount: 11111,
26
- text_amount: 'UNDICI MILIONI CENTOUNDICIMILA/00',
27
- company_name: 'ACME SRL',
28
- reason: 'LOREM IPSUM DOLOR SIT AMET, ADIPISCING CONSECTETUR ELIT',
29
- payer_name: 'MARIO ROSSI',
30
- address: {
31
- street: 'VIA FASULLA, 123',
32
- zip_code: '00100',
33
- city: 'ROMA',
34
- state: 'RM'
35
- }
36
- })
23
+ Postino::Form.new do |f|
24
+ f.account_number = '0123456789'
25
+ f.numeric_amount = 11111
26
+ f.text_amount = 'UNDICIMILACENTOUNDICI/00'
27
+ f.company_name = 'ACME SRL'
28
+ f.reason = 'LOREM IPSUM DOLOR SIT AMET, ADIPISCING CONSECTETUR ELIT'
29
+ f.payer_name = 'MARIO ROSSI'
30
+
31
+ f.address.configure do |a|
32
+ a.street = 'VIA FASULLA, 123'
33
+ a.zip_code = '00100'
34
+ a.city = 'ROMA'
35
+ a.state = 'RM'
36
+ end
37
+ end.generate('my_form.pdf')
37
38
  ```
38
39
 
39
40
  ## Contributing
data/lib/postino.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require "postino/version"
2
2
  require "postino/generator"
3
+ require "postino/form"
4
+ require "postino/form/address"
3
5
 
4
6
  module Postino
5
7
  end
@@ -0,0 +1,24 @@
1
+ require 'docile'
2
+
3
+ module Postino
4
+ class Form
5
+ attr_accessor :account_number, :text_amount, :numeric_amount, :payee_name,
6
+ :payer_name, :reason
7
+
8
+ attr_reader :address
9
+
10
+ def initialize(&block)
11
+ @address = Address.new
12
+ configure(&block) if block_given?
13
+ end
14
+
15
+ def configure(&block)
16
+ Docile.dsl_eval(self, self, &block)
17
+ self
18
+ end
19
+
20
+ def generate(path)
21
+ Postino::Generator.generate_form(path, self)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,22 @@
1
+ require 'docile'
2
+
3
+ module Postino
4
+ class Form
5
+ class Address
6
+ attr_accessor :street, :zip_code, :city, :state
7
+
8
+ def initialize(&block)
9
+ configure(&block) if block_given?
10
+ end
11
+
12
+ def configure(&block)
13
+ Docile.dsl_eval(self, self, &block)
14
+ self
15
+ end
16
+
17
+ def location
18
+ "#{city} (#{state})"
19
+ end
20
+ end
21
+ end
22
+ end
@@ -9,73 +9,113 @@ module Postino
9
9
  TEXT_AMOUNT_COORDINATES = [[515, 243], [87, 243]]
10
10
  REASON_COORDINATES = [[32, 180], [400, 180]]
11
11
  PAYER_NAME_COORDINATES = [[32, 138], [541, 143]]
12
+ COMPANY_NAME_COORDINATES = [[32, 220], [397, 220]]
13
+ ADDRESS_STREET_COORDINATES = [[60, 107], [540, 105]]
14
+ ADDRESS_ZIP_CODE_COORDINATES = [[60, 92], [540, 80]]
15
+ ADDRESS_LOCATION_COORDINATES = [[60, 77], [615, 80]]
16
+
17
+ # Generates a new postal payment form.
18
+ #
19
+ # @param path [String] The target path
20
+ # @param form [Postino::Form] The form model
21
+ def generate_form(path, form)
22
+ Prawn::Document.generate(path, template: TEMPLATE_PATH, margin: 0) do |pdf|
23
+ pdf.font 'Courier'
24
+ pdf.font_size 11
25
+
26
+ add_account_number(pdf, form)
27
+ add_text_amount(pdf, form)
28
+ add_numeric_amount(pdf, form)
29
+ add_payee_name(pdf, form)
30
+ add_reason(pdf, form)
31
+ add_payer_name(pdf, form)
32
+ add_address(pdf, form)
33
+ end
34
+ end
12
35
 
13
- def generate_form(path, options = {})
14
- options = normalize_options(options)
15
- options[:address] = normalize_options(options[:address])
16
-
17
- Prawn::Document.generate(path, template: TEMPLATE_PATH, skip_page_creation: true, margin: 0) do
18
- font 'Courier'
19
- font_size 11
36
+ protected
20
37
 
38
+ def add_account_number(pdf, form)
21
39
  ACCOUNT_NUMBER_COORDINATES.each do |coordinates|
22
- text_box options[:account_number], at: coordinates, character_spacing: 6
40
+ pdf.text_box form.account_number, at: coordinates, character_spacing: 6
23
41
  end
42
+ end
24
43
 
44
+ def add_text_amount(pdf, form)
25
45
  TEXT_AMOUNT_COORDINATES.each do |coordinates|
26
- text_box options[:text_amount], at: coordinates
46
+ pdf.text_box form.text_amount, at: coordinates
27
47
  end
48
+ end
28
49
 
29
- numeric_amount = ('%.2f' % options[:numeric_amount]).gsub('.', '')
50
+ def add_numeric_amount(pdf, form)
51
+ numeric_amount = ('%.2f' % form.numeric_amount).gsub('.', '')
30
52
  numeric_amount_y = 363 - 13 * numeric_amount.length
31
53
 
32
- [
33
- [numeric_amount_y, 257],
34
- [numeric_amount_y + 473, 257]
35
- ].each do |coordinates|
36
- text_box numeric_amount, at: coordinates, character_spacing: 6
54
+ [[numeric_amount_y, 257], [numeric_amount_y + 473, 257]].each do |coordinates|
55
+ pdf.text_box numeric_amount, at: coordinates, character_spacing: 6
37
56
  end
57
+ end
38
58
 
39
- text_box options[:company_name], at: [32, 220]
40
- text_box options[:company_name], at: [397, 220], character_spacing: 6
59
+ def add_payee_name(pdf, form)
60
+ pdf.text_box form.payee_name, at: COMPANY_NAME_COORDINATES[0], width: 300
61
+ pdf.text_box form.payee_name, at: COMPANY_NAME_COORDINATES[1], character_spacing: 6
62
+ end
41
63
 
42
- bounding_box(REASON_COORDINATES[0], width: 300, height: 100) do
43
- text_box options[:reason]
64
+ def add_reason(pdf, form)
65
+ pdf.bounding_box(REASON_COORDINATES[0], width: 300, height: 100) do
66
+ pdf.text_box form.reason
44
67
  end
45
68
 
46
- bounding_box(REASON_COORDINATES[1], width: 400, height: 100) do
47
- text_box options[:reason]
69
+ pdf.bounding_box(REASON_COORDINATES[1], width: 400, height: 100) do
70
+ pdf.text_box form.reason
48
71
  end
72
+ end
49
73
 
50
- bounding_box(PAYER_NAME_COORDINATES[0], width: 180, height: 100) do
51
- text_box options[:payer_name]
74
+ def add_payer_name(pdf, form)
75
+ pdf.bounding_box(PAYER_NAME_COORDINATES[0], width: 180, height: 100) do
76
+ pdf.text_box form.payer_name
52
77
  end
53
78
 
54
- bounding_box(PAYER_NAME_COORDINATES[1], width: 300, height: 100) do
55
- text_box options[:payer_name], character_spacing: 6
79
+ pdf.bounding_box(PAYER_NAME_COORDINATES[1], width: 300, height: 100) do
80
+ pdf.text_box form.payer_name, character_spacing: 5.7, height: 100, overflow: :truncate
56
81
  end
57
-
58
- text_box options[:address][:street], at: [60, 107], width: 130, height: 10, size: 9, overflow: :truncate
59
- text_box options[:address][:street], at: [540, 105], width: 300, height: 10, character_spacing: 6, overflow: :truncate
60
-
61
- text_box options[:address][:zip_code], at: [60, 92], size: 9
62
- text_box options[:address][:zip_code], at: [540, 80], character_spacing: 6
63
-
64
- location = "#{options[:address][:city]} (#{options[:address][:state]})"
65
-
66
- text_box location, at: [60, 77], width: 200, height: 10, size: 9, overflow: :truncate
67
- text_box location, at: [615, 80], width: 200, height: 10, character_spacing: 6, overflow: :truncate
68
82
  end
69
- end
70
-
71
- private
72
-
73
- def normalize_options(options)
74
- options.each do |key, value|
75
- value.upcase! if value.is_a?(String)
76
- end
77
83
 
78
- options
84
+ def add_address(pdf, form)
85
+ pdf.text_box(form.address.street,
86
+ at: ADDRESS_STREET_COORDINATES[0],
87
+ width: 130,
88
+ height: 10,
89
+ size: 9,
90
+ overflow: :truncate
91
+ )
92
+
93
+ pdf.text_box(form.address.street,
94
+ at: ADDRESS_STREET_COORDINATES[1],
95
+ width: 300,
96
+ height: 10,
97
+ character_spacing: 6,
98
+ overflow: :truncate
99
+ )
100
+
101
+ pdf.text_box form.address.zip_code, at: ADDRESS_ZIP_CODE_COORDINATES[0], size: 9
102
+ pdf.text_box form.address.zip_code, at: ADDRESS_ZIP_CODE_COORDINATES[1], character_spacing: 6
103
+
104
+ pdf.text_box(form.address.location,
105
+ at: ADDRESS_LOCATION_COORDINATES[0],
106
+ width: 200,
107
+ height: 10,
108
+ size: 9,
109
+ overflow: :truncate
110
+ )
111
+
112
+ pdf.text_box(form.address.location,
113
+ at: ADDRESS_LOCATION_COORDINATES[1],
114
+ width: 200,
115
+ height: 10,
116
+ character_spacing: 6,
117
+ overflow: :truncate
118
+ )
79
119
  end
80
120
  end
81
121
  end
@@ -1,3 +1,3 @@
1
1
  module Postino
2
- VERSION = "0.0.2"
2
+ VERSION = "1.0.0"
3
3
  end
data/postino.gemspec CHANGED
@@ -19,9 +19,11 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_runtime_dependency "prawn", '< 0.14'
22
+ spec.add_runtime_dependency "docile", '~> 1.1'
22
23
 
23
24
  spec.add_development_dependency "bundler", "~> 1.5"
24
25
  spec.add_development_dependency "rake", '~> 10.1'
25
26
  spec.add_development_dependency "rspec", '~> 2.14'
26
27
  spec.add_development_dependency "fuubar", '~> 1.3'
28
+ spec.add_development_dependency "mocha", '~> 1.0'
27
29
  end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe Postino::Form::Address do
4
+ subject { Postino::Form::Address.new }
5
+
6
+ describe '#configure' do
7
+ it 'takes a block for configuration' do
8
+ subject.configure do |a|
9
+ a.zip_code = '00100'
10
+ end.zip_code.should == '00100'
11
+ end
12
+ end
13
+
14
+ describe '#location' do
15
+ before do
16
+ subject.city = 'Roma'
17
+ subject.state = 'RM'
18
+ end
19
+
20
+ it 'returns the city and state' do
21
+ subject.location.should == 'Roma (RM)'
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe Postino::Form do
4
+ subject { Postino::Form.new }
5
+
6
+ describe '#configure' do
7
+ it 'takes a block for configuration' do
8
+ subject.configure do |f|
9
+ f.account_number = 'test'
10
+ end.account_number.should == 'test'
11
+ end
12
+ end
13
+
14
+ describe '#generate' do
15
+ it 'generates the PDF form' do
16
+ Postino::Generator.expects(:generate_form).once
17
+ subject.generate('test.pdf')
18
+ end
19
+ end
20
+ end
@@ -2,22 +2,30 @@ require 'spec_helper'
2
2
 
3
3
  describe Postino::Generator do
4
4
  describe '.generate_form' do
5
+ let(:form) do
6
+ Postino::Form.new do |f|
7
+ f.account_number = '1234567890'
8
+ f.numeric_amount = 11111
9
+ f.text_amount = 'UNDICIMILACENTOUNDICI/00'
10
+ f.payee_name = 'LOREM IPSUM DOLOR SIT AMET, ADIPISCING CONSECTETUR ELIT CORP.'
11
+ f.reason = 'LOREM IPSUM DOLOR SIT AMET, ADIPISCING CONSECTETUR ELIT.'
12
+ f.payer_name = 'MARIO ROSSI DI MONTEBIANCO'
13
+
14
+ f.address.configure do |a|
15
+ a.street = 'VIA FASULLA, 123'
16
+ a.zip_code = '00100'
17
+ a.city = 'ROMA'
18
+ a.state = 'RM'
19
+ end
20
+ end
21
+ end
22
+
5
23
  it 'generates the form' do
6
24
  expect {
7
- Postino::Generator.generate_form(File.expand_path('../form.pdf', __FILE__), {
8
- account_number: '0123456789',
9
- numeric_amount: 11111,
10
- text_amount: 'UNDICI MILIONI CENTOUNDICIMILA/00',
11
- company_name: 'ACME SRL',
12
- reason: 'LOREM IPSUM DOLOR SIT AMET, ADIPISCING CONSECTETUR ELIT',
13
- payer_name: 'MARIO ROSSI',
14
- address: {
15
- street: 'VIA FASULLA, 123',
16
- zip_code: '00100',
17
- city: 'ROMA',
18
- state: 'RM'
19
- }
20
- })
25
+ Postino::Generator.generate_form(
26
+ File.expand_path('../form.pdf', __FILE__),
27
+ form
28
+ )
21
29
  }.not_to raise_error
22
30
  end
23
31
  end
data/spec/spec_helper.rb CHANGED
@@ -11,6 +11,7 @@ RSpec.configure do |config|
11
11
  config.treat_symbols_as_metadata_keys_with_true_values = true
12
12
  config.run_all_when_everything_filtered = true
13
13
  config.filter_run :focus
14
+ config.mock_with :mocha
14
15
 
15
16
  # Run specs in random order to surface order dependencies. If you find an
16
17
  # order dependency and want to debug it, you can fix the order by providing
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postino
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessandro Desantis
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "<"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: docile
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.1'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +94,20 @@ dependencies:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
96
  version: '1.3'
97
+ - !ruby/object:Gem::Dependency
98
+ name: mocha
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.0'
83
111
  description: Postino is a gem that allows to generate Italian postal payment forms
84
112
  in PDF format using Prawn.
85
113
  email:
@@ -97,10 +125,13 @@ files:
97
125
  - Rakefile
98
126
  - assets/form.pdf
99
127
  - lib/postino.rb
128
+ - lib/postino/form.rb
129
+ - lib/postino/form/address.rb
100
130
  - lib/postino/generator.rb
101
131
  - lib/postino/version.rb
102
132
  - postino.gemspec
103
- - spec/postino/form.pdf
133
+ - spec/postino/address_spec.rb
134
+ - spec/postino/form_spec.rb
104
135
  - spec/postino/generator_spec.rb
105
136
  - spec/spec_helper.rb
106
137
  homepage: https://github.com/alessandro1997/postino
@@ -128,6 +159,7 @@ signing_key:
128
159
  specification_version: 4
129
160
  summary: A gem to generate Italian postal payment forms.
130
161
  test_files:
131
- - spec/postino/form.pdf
162
+ - spec/postino/address_spec.rb
163
+ - spec/postino/form_spec.rb
132
164
  - spec/postino/generator_spec.rb
133
165
  - spec/spec_helper.rb