mercosur_plate_converter 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 862163d8a94a20e03f1e3a769d06d2ac4b7ad088c53c97cc94f4f89cfc1fbcbc
4
+ data.tar.gz: 7ae93d28afe4a90a236d9af6ef2baf2242dfc1c268c94fe5f8a31cc43f61433b
5
+ SHA512:
6
+ metadata.gz: 68ac243bd0507c78c3100549afa807c35b15be3324534d9aa96d41d13e11e29d0cc8d9e7a366b24e7f5c5f1d7800aff027ef59408ed9ca8d86e8e005d24be6ec
7
+ data.tar.gz: 48dcc46e83c960c2ada799ab97b7e5fc4e62339a3e729d9d1d2ed41e7fb5f42d266e775a4d2f72e952a828249b60705a2239d2f7d1f46f675d40b9c50f6938db
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in mercosur_plate_converter.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.21"
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Renan Luiz Vendramini
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,70 @@
1
+ # MercosurPlateConverter
2
+
3
+ [ENGLISH 🇺🇸🇬🇧](README_en.md)
4
+
5
+ A motivação por trás dessa GEM é validar e converter placas de veículos brasileiros do antigo modelo para o novo modelo adotado pelo Mercosul (e vice-versa).
6
+
7
+ O padrão de numeração das placas de veículos brasileiros é o antigo modelo.
8
+ O padrão de numeração das placas de veículos mercosul é o novo modelo.
9
+
10
+ O padrão mercosul é composto por 3 letras, 1 número, 1 letra e 2 números.
11
+ Para fazer a conversão do modelo antigo para o novo, é necessário que o número seja convertido para a letra equivalente.
12
+ Essa conversão é feita a partir de uma sequência, como em um `Array`, onde cada elemento é uma letra de A a J de acordo com o índice desse `Array`.
13
+
14
+ Assim sendo:
15
+
16
+ |Número|Letra|
17
+ |-----|------|
18
+ |0|A|
19
+ |1|B|
20
+ |2|C|
21
+ |3|D|
22
+ |4|E|
23
+ |5|F|
24
+ |6|G|
25
+ |7|H|
26
+ |8|I|
27
+ |9|J|
28
+
29
+ ## Instalação
30
+
31
+ Insira a linha abaixo em seu Gemfile:
32
+
33
+ ```ruby
34
+ gem 'mercosur_plate_converter'
35
+ ```
36
+
37
+ E então execute no terminal:
38
+
39
+ $ bundle install
40
+
41
+ Ou instale manualmente, também via terminal:
42
+
43
+ $ gem install mercosur_plate_converter
44
+
45
+ ## Uso
46
+
47
+ Crie uma instância da classe MercosurPlateConverter e use os métodos para validar e converter placas.
48
+
49
+ O exemplo abaixo considera que você fornece uma placa válida do tipo Mercosul:
50
+
51
+ ```ruby
52
+ plate = MercosurPlateConverter.from_string("ABC1C34")
53
+
54
+ plate.original_plate #=> "ABC1C34"
55
+ plate.plate #=> "ABC1234"
56
+ plate.type #=> :mercosur
57
+ plate.valid? #=> true
58
+ plate.mercosur? #=> true
59
+ plate.old_brazilian? #=> false
60
+ ```
61
+
62
+ ## Desenvolvimento
63
+
64
+ Após verificar o repositório, execute `bin/setup` para instalar as dependências. Em seguida, execute `rake spec` para executar os testes. Você também pode executar `bin/console` para um prompt interativo que permitirá que você experimente.
65
+
66
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
67
+
68
+ ## Como contribuir?
69
+
70
+ Relatórios de bugs e pull requests são bem-vindos no GitHub em [github.com/rlvendramini/mercosur_plate_converter](https://github.com/rlvendramini/mercosur_plate_converter).
data/README_en.md ADDED
@@ -0,0 +1,70 @@
1
+ # MercosurPlateConverter
2
+
3
+ [PORTUGUESE 🇧🇷](README.md)
4
+
5
+ With this GEM you can validate and convert Brazilian plates from the old model to the new model used by Mercosul (and vice-versa).
6
+
7
+ The numbering standard for Brazilian vehicle license plates is the old model.
8
+ The mercosur vehicle license plate numbering standard is the new model.
9
+
10
+ The Mercosur standard is composed of 3 letters, 1 number, 1 letter and 2 numbers.
11
+ To convert from the old model to the new one, it is necessary that the number be converted to the equivalent letter.
12
+ This conversion is done from a sequence, as in an `Array`, where each element is a letter from A to J according to the index of that `Array`.
13
+
14
+ So, for example:
15
+
16
+ |Number|Letter|
17
+ |-----|------|
18
+ |0|A|
19
+ |1|B|
20
+ |2|C|
21
+ |3|D|
22
+ |4|E|
23
+ |5|F|
24
+ |6|G|
25
+ |7|H|
26
+ |8|I|
27
+ |9|J|
28
+
29
+ ## Installation
30
+
31
+ Add this line to your application's Gemfile:
32
+
33
+ ```ruby
34
+ gem 'mercosur_plate_converter'
35
+ ```
36
+
37
+ And then execute:
38
+
39
+ $ bundle install
40
+
41
+ Or install it yourself as:
42
+
43
+ $ gem install mercosur_plate_converter
44
+
45
+ ## Usage
46
+
47
+ Instantiate MercosurPlateConverter class and use the methods to validate and convert plates.
48
+
49
+ The example below assumes that you supply a valid Mercosur-type license plate:
50
+
51
+ ```ruby
52
+ plate = MercosurPlateConverter.from_string("ABC1C34")
53
+
54
+ plate.original_plate #=> "ABC1C34"
55
+ plate.plate #=> "ABC1234"
56
+ plate.type #=> :mercosur
57
+ plate.valid? #=> true
58
+ plate.mercosur? #=> true
59
+ plate.old_brazilian? #=> false
60
+ ```
61
+
62
+ ## Development
63
+
64
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
65
+
66
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
67
+
68
+ ## Contributing
69
+
70
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/mercosur_plate_converter.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "mercosur_plate_converter"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MercosurPlateConverter
4
+ # MercosurPlateConverter::Converter.new("ABC1C34") where "ABC1C34" is the vehicle's plate.
5
+ class Converter
6
+ FIFTH_TERM_MAP = ("A".."J").to_a.freeze
7
+
8
+ attr_reader :original_plate, :type, :plate
9
+
10
+ def initialize(plate)
11
+ @original_plate = sanitize_plate(plate)
12
+ @plate = @original_plate.dup
13
+ @type = nil
14
+
15
+ validate_plate
16
+ detect_type
17
+ convert
18
+ end
19
+
20
+ def convert
21
+ send("convert_from_#{type}")
22
+ end
23
+
24
+ def valid?
25
+ mercosur? || old_brazilian?
26
+ end
27
+
28
+ def mercosur?
29
+ @original_plate.match?(/^(BR\s?)?[A-Z]{3}[0-9]{1}[A-Z]{1}[0-9]{2}$/)
30
+ end
31
+
32
+ def old_brazilian?
33
+ @original_plate.match?(/^[A-Z]{3}[0-9]{4}$/)
34
+ end
35
+
36
+ private
37
+
38
+ def convert_from_old_brazilian
39
+ return @plate if @type == :mercosur
40
+
41
+ @plate[4] = FIFTH_TERM_MAP[@plate[4].to_i]
42
+ @plate
43
+ end
44
+
45
+ def convert_from_mercosur
46
+ return @plate if @type == :old_brazilian
47
+
48
+ @plate = @plate.gsub(/^(BR\s?)?/, "")
49
+ @plate[4] = FIFTH_TERM_MAP.index(@plate[4]).to_s
50
+ @plate
51
+ end
52
+
53
+ def detect_type
54
+ @type = if mercosur?
55
+ :mercosur
56
+ elsif old_brazilian?
57
+ :old_brazilian
58
+ end
59
+ end
60
+
61
+ def sanitize_plate(plate)
62
+ return unless plate
63
+
64
+ plate.to_s.upcase.gsub(/[^0-9A-Z]/, "")
65
+ end
66
+
67
+ def validate_plate
68
+ raise MissingPlateError, "Missing plate" if @plate.nil?
69
+ raise InvalidPlateError, "Invalid plate #{@plate}" unless valid?
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MercosurPlateConverter
4
+ class MissingPlateError < StandardError; end
5
+ class InvalidPlateError < StandardError; end
6
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MercosurPlateConverter
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "mercosur_plate_converter/version"
4
+ require_relative "mercosur_plate_converter/converter"
5
+ require_relative "mercosur_plate_converter/errors"
6
+
7
+ # MercoSurPlateConverter is a gem that converts Mercosur plates to Brazilian plates and vice versa.
8
+ # you can call it like this: MercosurPlateConverter.from_string("ABC1C34")
9
+ module MercosurPlateConverter
10
+ def self.from_string(plate)
11
+ Converter.new(plate)
12
+ end
13
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/mercosur_plate_converter/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "mercosur_plate_converter"
7
+ spec.version = MercosurPlateConverter::VERSION
8
+ spec.authors = ["Renan Luiz Vendramini"]
9
+ spec.email = ["renanlvendramini@gmail.com"]
10
+
11
+ spec.summary = "An easy converter of Mercosur plates to Brazilian plates."
12
+ spec.description = "I created this gem to convert Mercosur plates to Brazilian plates and vice versa."
13
+ spec.homepage = "https://github.com/rlvendramini/mercosur_plate_converter"
14
+ spec.required_ruby_version = ">= 2.6.0"
15
+ spec.license = "MIT"
16
+
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = "#{spec.homepage}/blob/master/mercosur_plate_converter.gemspec"
19
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/master/CHANGELOG.md"
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject do |f|
25
+ (f == __FILE__) || f.match(%r{\A(?:(?:test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
26
+ end
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ # Uncomment to register a new dependency of your gem
33
+ # spec.add_dependency "example-gem", "~> 1.0"
34
+ spec.add_development_dependency "rspec", "~> 3.0"
35
+ spec.add_development_dependency "rubocop", "~> 1.2"
36
+ spec.add_development_dependency "rubocop-rake", "~> 0.6.0"
37
+ spec.add_development_dependency "rubocop-rspec", "~> 2.9.0"
38
+ spec.add_development_dependency "simplecov", "~> 0.21.2"
39
+
40
+ # For more information and examples about making a new gem, check out our
41
+ # guide at: https://bundler.io/guides/creating_gem.html
42
+ end
@@ -0,0 +1,4 @@
1
+ module MercosurPlateConverter
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mercosur_plate_converter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Renan Luiz Vendramini
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-03-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.2'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop-rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.6.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.6.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rubocop-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.9.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.9.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.21.2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.21.2
83
+ description: I created this gem to convert Mercosur plates to Brazilian plates and
84
+ vice versa.
85
+ email:
86
+ - renanlvendramini@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".rspec"
92
+ - ".rubocop.yml"
93
+ - Gemfile
94
+ - LICENSE
95
+ - README.md
96
+ - README_en.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - lib/mercosur_plate_converter.rb
101
+ - lib/mercosur_plate_converter/converter.rb
102
+ - lib/mercosur_plate_converter/errors.rb
103
+ - lib/mercosur_plate_converter/version.rb
104
+ - mercosur_plate_converter.gemspec
105
+ - sig/mercosur_plate_converter.rbs
106
+ homepage: https://github.com/rlvendramini/mercosur_plate_converter
107
+ licenses:
108
+ - MIT
109
+ metadata:
110
+ homepage_uri: https://github.com/rlvendramini/mercosur_plate_converter
111
+ source_code_uri: https://github.com/rlvendramini/mercosur_plate_converter/blob/master/mercosur_plate_converter.gemspec
112
+ changelog_uri: https://github.com/rlvendramini/mercosur_plate_converter/blob/master/CHANGELOG.md
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: 2.6.0
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubygems_version: 3.3.3
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: An easy converter of Mercosur plates to Brazilian plates.
132
+ test_files: []