qr-bills 0.2.2 → 0.3

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
  SHA256:
3
- metadata.gz: 673b6c6cd7948ecf8121a1cff9462c6d60a7c8b1022078fae2eb463919885dc7
4
- data.tar.gz: 765e8d32630c70b9b8441e0cc8613821ba8e683bd9324293adc3ebdea4ec785d
3
+ metadata.gz: f0f5417c130ea2bb955adc879dabbc2e93f470c3990bd7b79cc5c9d069a92aca
4
+ data.tar.gz: 412fd936ffa901e2d83909215c5dfe5e700945d76ae0ca8b3b4e4ea3d48f8740
5
5
  SHA512:
6
- metadata.gz: bcb1a9f90fae5d55d14d2452212a47a29fa6049e9f1f86cc9ed682824424614a5909095b69aa0adc4f2b8d1f092fcc9fd56316b8742c559ba571acaaaba7a282
7
- data.tar.gz: 58723203eeb46a9948ed5d37fcb35603c2e6abb7a294d351c30c7f3e26629fc0a4eecfd493aa947cef794a25fdc56c6a73432f57be3a373ce5c9fe2146c1b28d
6
+ metadata.gz: a1448d54d8fddc9ae2e11fa8d900fa21f0a2c0d501360a6386636a9650200c53f3b487c0aa05d1acfb8909e2ab816ee57c1c70ce88d08f84ecfe903c1f09883e
7
+ data.tar.gz: 5787cc90e6a2546736376f7268bc13e044cfd06b0783b4876e77d12ff1d8f465c02cc804377e6cfe64074ac329e3f5025837f5de221d3f2391f6d169d8820209
data/lib/qr-bills.rb CHANGED
@@ -4,41 +4,32 @@ require 'qr-bills/qr-params'
4
4
  require 'qr-bills/qr-html-layout'
5
5
  require 'qr-bills/qr-creditor-reference'
6
6
 
7
- class QRBills
7
+ module QRBills
8
8
  def self.generate(qr_params)
9
+ raise ArgumentError, "#{QRExceptions::INVALID_PARAMETERS}: bill type param not set" unless qr_params.has_key?(:bill_type)
10
+ raise ArgumentError, "#{QRExceptions::INVALID_PARAMETERS}: validation failed" unless QRParams.valid?(qr_params)
9
11
 
10
- # params validation
11
- if qr_params.has_key?(:bill_type)
12
-
13
- if !QRParams.valid?(qr_params)
14
- raise QRExceptions::INVALID_PARAMETERS + ": params validation check failed"
15
- end
12
+ # init translator sets
13
+ %i[it en de fr].each do |locale|
14
+ locale_file = File.join(qr_params[:locales][:path], "qrbills.#{locale}.yml")
16
15
 
17
- if !qr_params[:output_params][:format] == "html"
18
- raise QRExceptions::NOT_SUPPORTED + ": html is the only output format supported so far"
19
- end
16
+ I18n.load_path << locale_file
17
+ end
20
18
 
19
+ output = case qr_params[:output_params][:format]
20
+ when 'html'
21
+ QRHTMLLayout.create(qr_params)
22
+ when 'qrcode_png'
23
+ QRGenerator.create(qr_params, qr_params[:qrcode_filepath])
21
24
  else
22
- raise QRExceptions::INVALID_PARAMETERS + ": bill type param not set"
25
+ raise ArgumentError, "#{QRExceptions::NOT_SUPPORTED}: #{qr_params[:output_params][:format]} is not yet supported"
23
26
  end
24
27
 
25
- # init translator sets
26
- I18n.load_path << File.join(qr_params[:locales][:path], "qrbills.it.yml")
27
- I18n.load_path << File.join(qr_params[:locales][:path], "qrbills.en.yml")
28
- I18n.load_path << File.join(qr_params[:locales][:path], "qrbills.de.yml")
29
- I18n.load_path << File.join(qr_params[:locales][:path], "qrbills.fr.yml")
30
- I18n.default_locale = :it
31
-
32
- bill = {
33
- params: qr_params,
34
- output: QRHTMLLayout.create(qr_params)
35
- }
36
-
37
- return bill
28
+ { params: qr_params, output: output }
38
29
  end
39
30
 
40
31
  def self.create_creditor_reference(reference)
41
- return QRCreditorReference.create(reference)
32
+ QRCreditorReference.create(reference)
42
33
  end
43
34
 
44
35
  def self.get_qr_params
@@ -1,7 +1,7 @@
1
1
  require 'qr-bills/qr-exceptions'
2
2
 
3
3
  # implement Creditor Reference ISO 11649 generator
4
- class QRCreditorReference
4
+ module QRCreditorReference
5
5
  PREFIX = "RF"
6
6
 
7
7
  @char_values = {
@@ -1,4 +1,4 @@
1
- class QRExceptions
1
+ module QRExceptions
2
2
  EXCEPTION_PREFIX = "QR-bill"
3
3
 
4
4
  INVALID_PARAMETERS = EXCEPTION_PREFIX + " invalid parameters"
@@ -1,8 +1,6 @@
1
1
  require 'rqrcode'
2
- require 'rmagick'
3
- include Magick
4
2
 
5
- class QRGenerator
3
+ module QRGenerator
6
4
  # payload:
7
5
  # "SPC\r\n" + # indicator for swiss qr code: SPC (swiss payments code)
8
6
  # "0200\r\n" + # version of the specifications, 0200 = v2.0
@@ -39,11 +37,6 @@ class QRGenerator
39
37
  # "eBill/B/41010560425610173"; # alternative scheme paramaters, max 100 chars
40
38
 
41
39
  def self.create(params, qrcode_path)
42
- create_qr(params, qrcode_path)
43
- add_swiss_cross(qrcode_path, qrcode_path)
44
- end
45
-
46
- def self.create_qr(params, qrcode_path)
47
40
  payload = "SPC\r\n"
48
41
  payload += "0200\r\n"
49
42
  payload += "1\r\n"
@@ -93,13 +86,8 @@ class QRGenerator
93
86
  size: 1024,
94
87
  )
95
88
 
96
- IO.binwrite(qrcode_path, png.to_s)
97
- end
98
-
99
- def self.add_swiss_cross(qrcode_path, final_path)
100
- qr_image = Image.read(qrcode_path)[0]
101
- swiss_cross = Image.read(File.expand_path("#{File.dirname(__FILE__)}/../../web/assets/images/swiss_cross.png"))[0]
102
- final_qr = qr_image.composite(swiss_cross, CenterGravity, OverCompositeOp)
103
- final_qr.write(final_path)
89
+ swiss_cross = ChunkyPNG::Image.from_file(File.expand_path("#{File.dirname(__FILE__)}/../../web/assets/images/swiss_cross.png"))
90
+ final_qr = png.compose!(swiss_cross, (png.width - swiss_cross.width) / 2, (png.height - swiss_cross.height) / 2)
91
+ final_qr.save(qrcode_path)
104
92
  end
105
93
  end
@@ -1,6 +1,6 @@
1
1
  require 'qr-bills/qr-generator'
2
2
 
3
- class QRHTMLLayout
3
+ module QRHTMLLayout
4
4
 
5
5
  def self.create(params)
6
6
  QRGenerator.create(params, params[:qrcode_filepath])
@@ -1,7 +1,7 @@
1
- class QRParams
1
+ module QRParams
2
2
  QR_BILL_WITH_QR_REFERENCE = "orange_with_reference"
3
3
  QR_BILL_WITH_CREDITOR_REFERENCE = "red_with_reference"
4
- QR_BILL_WITOUTH_REFERENCE = "red_without_reference"
4
+ QR_BILL_WITHOUT_REFERENCE = "red_without_reference"
5
5
 
6
6
  def self.get_qr_params
7
7
  {
@@ -56,43 +56,38 @@ class QRParams
56
56
  end
57
57
 
58
58
  def self.valid?(params)
59
- if params.has_key?(:bill_type)
59
+ return false unless params.key?(:bill_type)
60
+ return false unless QRParams.base_params_valid?(params)
60
61
 
61
- if !QRParams.base_params_valid?(params)
62
- return false
63
- end
64
-
65
- if params[:bill_type] == QR_BILL_WITH_QR_REFERENCE
66
- return QRParams.qr_bill_with_qr_reference_valid?(params)
67
- elsif params[:bill_type] == QR_BILL_WITH_CREDITOR_REFERENCE
68
- return QRParams.qr_bill_with_creditor_reference_valid?(params)
69
- elsif params[:bill_type] == QR_BILL_WITOUTH_REFERENCE
70
- return QRParams.qr_bill_without_reference_valid?(params)
71
- else
72
- return false
73
- end
62
+ case params[:bill_type]
63
+ when QRParams::QR_BILL_WITH_QR_REFERENCE
64
+ QRParams.qr_bill_with_qr_reference_valid?(params)
65
+ when QRParams::QR_BILL_WITH_CREDITOR_REFERENCE
66
+ QRParams.qr_bill_with_creditor_reference_valid?(params)
67
+ when QRParams::QR_BILL_WITHOUT_REFERENCE
68
+ QRParams.qr_bill_without_reference_valid?(params)
74
69
  else
75
- return false
70
+ false
76
71
  end
77
72
  end
78
-
73
+
79
74
  def self.base_params_valid?(params)
80
- # todo
81
- return true
75
+ # TODO
76
+ true
82
77
  end
83
78
 
84
79
  def self.qr_bill_with_qr_reference_valid?(params)
85
- # todo
86
- return true
80
+ # TODO
81
+ true
87
82
  end
88
83
 
89
84
  def self.qr_bill_with_creditor_reference_valid?(params)
90
- # todo
91
- return true
85
+ # TODO
86
+ true
92
87
  end
93
88
 
94
89
  def self.qr_bill_without_reference_valid?(params)
95
- # todo
96
- return true
90
+ # TODO
91
+ true
97
92
  end
98
93
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qr-bills
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damiano Radice
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-11 00:00:00.000000000 Z
11
+ date: 2021-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n
@@ -50,26 +50,6 @@ dependencies:
50
50
  - - "<"
51
51
  - !ruby/object:Gem::Version
52
52
  version: '2'
53
- - !ruby/object:Gem::Dependency
54
- name: rmagick
55
- requirement: !ruby/object:Gem::Requirement
56
- requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- version: 4.1.2
60
- - - "<"
61
- - !ruby/object:Gem::Version
62
- version: '5'
63
- type: :runtime
64
- prerelease: false
65
- version_requirements: !ruby/object:Gem::Requirement
66
- requirements:
67
- - - ">="
68
- - !ruby/object:Gem::Version
69
- version: 4.1.2
70
- - - "<"
71
- - !ruby/object:Gem::Version
72
- version: '5'
73
53
  - !ruby/object:Gem::Dependency
74
54
  name: rspec
75
55
  requirement: !ruby/object:Gem::Requirement
@@ -100,7 +80,7 @@ dependencies:
100
80
  version: '13.0'
101
81
  description: 'QR-bills support for swiss payments, for full documentation please refer
102
82
  to github repo: https://github.com/damoiser/qr-bills'
103
- email: damoiser+qrbill@gmail.com
83
+ email: dam.radice@gmail.com
104
84
  executables: []
105
85
  extensions: []
106
86
  extra_rdoc_files: []
@@ -133,7 +113,7 @@ metadata:
133
113
  homepage_uri: https://github.com/damoiser/qr-bills
134
114
  source_code_uri: https://github.com/damoiser/qr-bills
135
115
  wiki_uri: https://github.com/damoiser/qr-bills
136
- post_install_message:
116
+ post_install_message:
137
117
  rdoc_options: []
138
118
  require_paths:
139
119
  - lib
@@ -149,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
149
129
  version: '0'
150
130
  requirements: []
151
131
  rubygems_version: 3.1.2
152
- signing_key:
132
+ signing_key:
153
133
  specification_version: 4
154
134
  summary: QR-bills support for swiss payments
155
135
  test_files: []