postino 0.0.2
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 +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +45 -0
- data/Rakefile +6 -0
- data/assets/form.pdf +0 -0
- data/lib/postino/generator.rb +82 -0
- data/lib/postino/version.rb +3 -0
- data/lib/postino.rb +5 -0
- data/postino.gemspec +27 -0
- data/spec/postino/form.pdf +2680 -7
- data/spec/postino/generator_spec.rb +24 -0
- data/spec/spec_helper.rb +20 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9588e87c9cb359ec02b8fd9f6a9549a1c8b4cc86
|
4
|
+
data.tar.gz: 73bd081ec9df15a88d643f9e63d9df9d64afaf76
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b14318f8ce294332acfe76abf0f9dba5010567a7aedefa651076ec00b3bf79a36316f86c687a303ee37f53b3e0b77804d9d7d6d5178e90ee563eadb8bcee7114
|
7
|
+
data.tar.gz: bbc992f899f2c55d4439edf3c10d71f5c6b2fc2dde2af12c558cb870561db853ad5cc7d3ae539ddb7410f569c301f8c7bcb9a8c2f4df6e1d153825a56bccc39c
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Alessandro Desantis
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# Postino [](https://travis-ci.org/alessandro1997/postino) [](https://gemnasium.com/alessandro1997/postino)
|
2
|
+
|
3
|
+
[Postino](https://github.com/alessandro1997/postino) is a Ruby gem that allows to quickly generate Italian postal
|
4
|
+
payment forms in PDF format using [Prawn](https://github.com/prawnpdf/prawn).
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'postino'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install postino
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
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
|
+
})
|
37
|
+
```
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
1. [Fork it](http://github.com/alessandro1997/postino/fork)
|
42
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
43
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
44
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
45
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/assets/form.pdf
ADDED
Binary file
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'prawn'
|
2
|
+
|
3
|
+
module Postino
|
4
|
+
class Generator
|
5
|
+
class << self
|
6
|
+
TEMPLATE_PATH = File.expand_path('../../../assets/form.pdf', __FILE__)
|
7
|
+
|
8
|
+
ACCOUNT_NUMBER_COORDINATES = [[96, 258], [473, 258]]
|
9
|
+
TEXT_AMOUNT_COORDINATES = [[515, 243], [87, 243]]
|
10
|
+
REASON_COORDINATES = [[32, 180], [400, 180]]
|
11
|
+
PAYER_NAME_COORDINATES = [[32, 138], [541, 143]]
|
12
|
+
|
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
|
20
|
+
|
21
|
+
ACCOUNT_NUMBER_COORDINATES.each do |coordinates|
|
22
|
+
text_box options[:account_number], at: coordinates, character_spacing: 6
|
23
|
+
end
|
24
|
+
|
25
|
+
TEXT_AMOUNT_COORDINATES.each do |coordinates|
|
26
|
+
text_box options[:text_amount], at: coordinates
|
27
|
+
end
|
28
|
+
|
29
|
+
numeric_amount = ('%.2f' % options[:numeric_amount]).gsub('.', '')
|
30
|
+
numeric_amount_y = 363 - 13 * numeric_amount.length
|
31
|
+
|
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
|
37
|
+
end
|
38
|
+
|
39
|
+
text_box options[:company_name], at: [32, 220]
|
40
|
+
text_box options[:company_name], at: [397, 220], character_spacing: 6
|
41
|
+
|
42
|
+
bounding_box(REASON_COORDINATES[0], width: 300, height: 100) do
|
43
|
+
text_box options[:reason]
|
44
|
+
end
|
45
|
+
|
46
|
+
bounding_box(REASON_COORDINATES[1], width: 400, height: 100) do
|
47
|
+
text_box options[:reason]
|
48
|
+
end
|
49
|
+
|
50
|
+
bounding_box(PAYER_NAME_COORDINATES[0], width: 180, height: 100) do
|
51
|
+
text_box options[:payer_name]
|
52
|
+
end
|
53
|
+
|
54
|
+
bounding_box(PAYER_NAME_COORDINATES[1], width: 300, height: 100) do
|
55
|
+
text_box options[:payer_name], character_spacing: 6
|
56
|
+
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
|
+
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
|
+
|
78
|
+
options
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
data/lib/postino.rb
ADDED
data/postino.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'postino/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "postino"
|
8
|
+
spec.version = Postino::VERSION
|
9
|
+
spec.authors = ["Alessandro Desantis"]
|
10
|
+
spec.email = ["desa.alessandro@gmail.com"]
|
11
|
+
spec.summary = %q{A gem to generate Italian postal payment forms.}
|
12
|
+
spec.description = %q{Postino is a gem that allows to generate Italian postal payment forms in PDF format using Prawn.}
|
13
|
+
spec.homepage = "https://github.com/alessandro1997/postino"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "prawn", '< 0.14'
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
24
|
+
spec.add_development_dependency "rake", '~> 10.1'
|
25
|
+
spec.add_development_dependency "rspec", '~> 2.14'
|
26
|
+
spec.add_development_dependency "fuubar", '~> 1.3'
|
27
|
+
end
|