Skip to content

Commit 70c6536

Browse files
authored
Rubocop setup (#1)
1 parent 3cde40e commit 70c6536

File tree

8 files changed

+94
-53
lines changed

8 files changed

+94
-53
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
ruby-version: [2.7, 3.0]
10+
ruby-version: [2.3, 2.4, 2.5, 2.6, 2.7, 3.0]
1111
env:
1212
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}
1313
steps:

.rubocop.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
AllCops:
2+
NewCops: enable
3+
SuggestExtensions: false
4+
Exclude:
5+
- spec/*
6+
7+
Layout/LineLength:
8+
Max: 120
9+
Exclude:
10+
- qrcode_pix_ruby.gemspec
11+
12+
Metrics/MethodLength:
13+
Max: 20
14+
15+
Gemspec/RequiredRubyVersion:
16+
Enabled: false
17+
18+
Style/Documentation:
19+
Enabled: false
20+
21+
Metrics/AbcSize:
22+
Enabled: false
23+
24+
Metrics/BlockNesting:
25+
Enabled: false
26+
27+
Style/IfUnlessModifier:
28+
Enabled: false

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## [Unreleased]
22

3+
## [0.3.3] - 2021-06-25
4+
5+
- Rubocop setup
6+
- Add rubies 2.3, 2.4, 2.5 and 2.6 to support of gem
7+
38
## [0.3.2] - 2021-06-24
49

510
- Setup for run tests/specs locally with Docker

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
[![Gem](https://img.shields.io/gem/dt/qrcode_pix_ruby.svg)]()
88
[![license](https://img.shields.io/github/license/pedrofurtado/qrcode_pix_ruby.svg)]()
99
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/pedrofurtado/qrcode_pix_ruby)
10+
[![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop/rubocop)
1011

1112
Ruby gem for Qrcode generation of Pix (Pagamento Instantâneo Brasileiro - Banco Central do Brasil).
1213

@@ -83,8 +84,8 @@ git clone https://github.com/pedrofurtado/qrcode_pix_ruby
8384
cd qrcode_pix_ruby/
8485
docker build -t qrcode_pix_ruby_specs .
8586

86-
# Then, run this command how many times you want,
87-
# after editing local files, and so on, to get
87+
# Then, run this command how many times you want,
88+
# after editing local files, and so on, to get
8889
# feedback from test suite of gem.
8990
docker run -v $(pwd):/app/ -it qrcode_pix_ruby_specs
9091
```

Rakefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22

33
require 'bundler/gem_tasks'
44
require 'rspec/core/rake_task'
5+
require 'rubocop/rake_task'
56
RSpec::Core::RakeTask.new(:spec)
6-
task default: %i[spec]
7+
RuboCop::RakeTask.new
8+
task default: %i[spec rubocop]

lib/qrcode_pix_ruby/payload.rb

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@
44

55
module QrcodePixRuby
66
class Payload
7-
ID_PAYLOAD_FORMAT_INDICATOR = '00'.freeze
8-
ID_POINT_OF_INITIATION_METHOD = '01'.freeze
9-
ID_MERCHANT_ACCOUNT_INFORMATION = '26'.freeze
10-
ID_MERCHANT_ACCOUNT_INFORMATION_GUI = '00'.freeze
11-
ID_MERCHANT_ACCOUNT_INFORMATION_KEY = '01'.freeze
12-
ID_MERCHANT_ACCOUNT_INFORMATION_DESCRIPTION = '02'.freeze
13-
ID_MERCHANT_CATEGORY_CODE = '52'.freeze
14-
ID_TRANSACTION_CURRENCY = '53'.freeze
15-
ID_TRANSACTION_AMOUNT = '54'.freeze
16-
ID_COUNTRY_CODE = '58'.freeze
17-
ID_MERCHANT_NAME = '59'.freeze
18-
ID_MERCHANT_CITY = '60'.freeze
19-
ID_POSTAL_CODE = '61'.freeze
20-
ID_ADDITIONAL_DATA_FIELD_TEMPLATE = '62'.freeze
21-
ID_ADDITIONAL_DATA_FIELD_TEMPLATE_TXID = '05'.freeze
22-
ID_CRC16 = '63'.freeze
7+
ID_PAYLOAD_FORMAT_INDICATOR = '00'
8+
ID_POINT_OF_INITIATION_METHOD = '01'
9+
ID_MERCHANT_ACCOUNT_INFORMATION = '26'
10+
ID_MERCHANT_ACCOUNT_INFORMATION_GUI = '00'
11+
ID_MERCHANT_ACCOUNT_INFORMATION_KEY = '01'
12+
ID_MERCHANT_ACCOUNT_INFORMATION_DESCRIPTION = '02'
13+
ID_MERCHANT_CATEGORY_CODE = '52'
14+
ID_TRANSACTION_CURRENCY = '53'
15+
ID_TRANSACTION_AMOUNT = '54'
16+
ID_COUNTRY_CODE = '58'
17+
ID_MERCHANT_NAME = '59'
18+
ID_MERCHANT_CITY = '60'
19+
ID_POSTAL_CODE = '61'
20+
ID_ADDITIONAL_DATA_FIELD_TEMPLATE = '62'
21+
ID_ADDITIONAL_DATA_FIELD_TEMPLATE_TXID = '05'
22+
ID_CRC16 = '63'
2323

2424
attr_accessor :pix_key,
2525
:repeatable,
@@ -33,7 +33,7 @@ class Payload
3333
:amount
3434

3535
def payload
36-
p = ''
36+
p = ''
3737

3838
p += emv(ID_PAYLOAD_FORMAT_INDICATOR, '01')
3939
p += emv_repeatable
@@ -51,7 +51,17 @@ def payload
5151
end
5252

5353
def base64
54-
::RQRCode::QRCode.new(payload).as_png(bit_depth: 1, border_modules: 0, color_mode: 0, color: 'black', file: nil, fill: 'white', module_px_size: 6, resize_exactly_to: false, resize_gte_to: false).to_data_url
54+
::RQRCode::QRCode.new(payload).as_png(
55+
bit_depth: 1,
56+
border_modules: 0,
57+
color_mode: 0,
58+
color: 'black',
59+
file: nil,
60+
fill: 'white',
61+
module_px_size: 6,
62+
resize_exactly_to: false,
63+
resize_gte_to: false
64+
).to_data_url
5565
end
5666

5767
private
@@ -66,41 +76,34 @@ def emv_repeatable
6676
end
6777

6878
def emv_merchant
69-
merchant_gui = emv ID_MERCHANT_ACCOUNT_INFORMATION_GUI, 'BR.GOV.BCB.PIX'
70-
merchant_pix_key = emv ID_MERCHANT_ACCOUNT_INFORMATION_KEY, pix_key
79+
merchant_gui = emv(ID_MERCHANT_ACCOUNT_INFORMATION_GUI, 'BR.GOV.BCB.PIX')
80+
merchant_pix_key = emv(ID_MERCHANT_ACCOUNT_INFORMATION_KEY, pix_key)
7181
merchant_description = emv(ID_MERCHANT_ACCOUNT_INFORMATION_DESCRIPTION, description) if description
72-
73-
emv ID_MERCHANT_ACCOUNT_INFORMATION, "#{merchant_gui}#{merchant_pix_key}#{merchant_description}"
82+
emv(ID_MERCHANT_ACCOUNT_INFORMATION, "#{merchant_gui}#{merchant_pix_key}#{merchant_description}")
7483
end
7584

7685
def emv_additional_data
7786
txid = emv(ID_ADDITIONAL_DATA_FIELD_TEMPLATE_TXID, transaction_id || '***')
78-
emv ID_ADDITIONAL_DATA_FIELD_TEMPLATE, txid
87+
emv(ID_ADDITIONAL_DATA_FIELD_TEMPLATE, txid)
7988
end
8089

81-
def crc16(t)
82-
extended_payload = "#{t}#{ID_CRC16}04"
90+
def crc16(text)
91+
extended_payload = "#{text}#{ID_CRC16}04"
8392
extended_payload_length = extended_payload.length
8493
polynomial = 0x1021
8594
result = 0xFFFF
8695

87-
if extended_payload_length > 0
96+
if extended_payload_length.positive?
8897
offset = 0
8998

9099
while offset < extended_payload_length
91-
result = result ^ (extended_payload[offset].bytes[0] << 8)
92-
100+
result ^= extended_payload[offset].bytes[0] << 8
93101
bitwise = 0
94102

95103
while bitwise < 8
96-
result = result << 1
97-
98-
if result & 0x10000 != 0
99-
result = result ^ polynomial
100-
end
101-
102-
result = result & 0xFFFF
103-
104+
result <<= 1
105+
result ^= polynomial if result & 0x10000 != 0
106+
result &= 0xFFFF
104107
bitwise += 1
105108
end
106109

lib/qrcode_pix_ruby/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module QrcodePixRuby
4-
VERSION = '0.3.2'.freeze
4+
VERSION = '0.3.3'
55
end

qrcode_pix_ruby.gemspec

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ require_relative 'lib/qrcode_pix_ruby/version'
55
Gem::Specification.new do |spec|
66
spec.name = 'qrcode_pix_ruby'
77
spec.version = QrcodePixRuby::VERSION
8-
spec.authors = ["Pedro Furtado", "Marcio de Jesus", "William Radi", "Leonardo Comar"]
9-
spec.email = ["pedro.felipe.azevedo.furtado@gmail.com", "marciodejesusrj@gmail.com", "williamw@lbv.org.br", "lfcomar@lbv.org.br"]
10-
spec.summary = "Ruby gem for Qrcode generation of Pix (Pagamento Instantâneo Brasileiro - Banco Central do Brasil)"
11-
spec.description = "Ruby gem for Qrcode generation of Pix (Pagamento Instantâneo Brasileiro - Banco Central do Brasil)"
12-
spec.homepage = "https://github.com/pedrofurtado/qrcode_pix_ruby"
13-
spec.license = "MIT"
14-
spec.metadata["homepage_uri"] = spec.homepage
15-
spec.metadata["source_code_uri"] = spec.homepage
16-
spec.metadata["changelog_uri"] = "#{spec.homepage}/CHANGELOG.md"
8+
spec.authors = ['Pedro Furtado', 'Marcio de Jesus', 'William Radi', 'Leonardo Comar']
9+
spec.email = ['pedro.felipe.azevedo.furtado@gmail.com', 'marciodejesusrj@gmail.com', 'williamw@lbv.org.br', 'lfcomar@lbv.org.br']
10+
spec.summary = 'Ruby gem for Qrcode generation of Pix (Pagamento Instantâneo Brasileiro - Banco Central do Brasil)'
11+
spec.description = 'Ruby gem for Qrcode generation of Pix (Pagamento Instantâneo Brasileiro - Banco Central do Brasil)'
12+
spec.homepage = 'https://github.com/pedrofurtado/qrcode_pix_ruby'
13+
spec.license = 'MIT'
14+
spec.metadata['homepage_uri'] = spec.homepage
15+
spec.metadata['source_code_uri'] = spec.homepage
16+
spec.metadata['changelog_uri'] = "#{spec.homepage}/CHANGELOG.md"
17+
spec.required_ruby_version = '>= 2.3.0'
1718

1819
spec.files = Dir.chdir(File.expand_path(__dir__)) do
1920
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
@@ -23,7 +24,8 @@ Gem::Specification.new do |spec|
2324
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
2425
spec.require_paths = ['lib']
2526

26-
spec.add_dependency 'rake', '~> 13.0'
27-
spec.add_dependency 'rspec', '~> 3.0'
28-
spec.add_dependency 'rqrcode', '~> 2.0'
27+
spec.add_dependency 'rqrcode'
28+
spec.add_development_dependency 'rake'
29+
spec.add_development_dependency 'rspec'
30+
spec.add_development_dependency 'rubocop'
2931
end

0 commit comments

Comments
 (0)