cuitar 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 20ff1454cc92d75b0a189f3c8bf3e96034589c714d3ba87f9d5f1407557ba0df
4
+ data.tar.gz: ed8274b5b49cb0092291c8c6aee810ca0e049803e1a5924520ad52b4ebe52996
5
+ SHA512:
6
+ metadata.gz: '0822a51e245202b439f164e546ebfea756f9cdd0dcb37be94d5b97b4d184a41c8daf929cbaaf11d115eef3bd85df26384892e65c35713ecff7eae6615a294bf8'
7
+ data.tar.gz: cece5b93f180399ce3c7458529c28b0f80e3fded1461670f1d201fc375ef9427bbd4c76b365f356cf5a35ab62c3a5ed0f2100743c3fce1c44575b66b86777901
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.6.3
6
+ before_install: gem install bundler -v 2.1.4
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'rake', '~> 12.0'
6
+ gem 'minitest', '~> 5.0'
@@ -0,0 +1,21 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cuitar (1.0.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ minitest (5.14.2)
10
+ rake (12.3.1)
11
+
12
+ PLATFORMS
13
+ ruby
14
+
15
+ DEPENDENCIES
16
+ cuitar!
17
+ minitest (~> 5.0)
18
+ rake (~> 12.0)
19
+
20
+ BUNDLED WITH
21
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Sebastian Rabuini
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
13
+ all 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
21
+ THE SOFTWARE.
@@ -0,0 +1,52 @@
1
+ # Cuitar
2
+
3
+ Agrega la clase `Cuit` que permite validar y formatear una CUIT (Clave Única de
4
+ Identificación Tributaria argentina).
5
+
6
+ ## Instalación
7
+
8
+ Agregar en el Gemfile de la aplicación
9
+
10
+ ```ruby
11
+ gem 'cuitar'
12
+ ```
13
+
14
+ Y luego ejecutar:
15
+
16
+ $ bundle install
17
+
18
+ O manualmente ejecutando en la línea de comando:
19
+
20
+ $ gem install cuitar
21
+
22
+ ## Uso
23
+
24
+ Se crea el objecto Cuit de la siguiente forma:
25
+
26
+ ```ruby
27
+ cuit_number = '20228518310' # o '20-22851831-0' o 20228518310
28
+
29
+ cuit = Cuit.new(cuit_number)
30
+
31
+ cuit.valid? # => true
32
+
33
+ cuit.to_s # => '20-22851831-0'
34
+ ```
35
+
36
+ `cuit_number` puede pasarse de cualquiera de las siguientes tres formas:
37
+
38
+ * Un `String` conteniendo los 11 números que componen una CUIT.
39
+
40
+ * Un `String` conteniendo los 11 números que componen una CUIT, formateado con guiones.
41
+
42
+ * Un `Integer` comprendido por los 11 números que componen una CUIT.
43
+
44
+
45
+ ## Contribuciones
46
+
47
+ Reporte de errores y pull requests son bienvenidos en https://github.com/srabuini/cuitar.
48
+
49
+
50
+ ## Licencia
51
+
52
+ Disponible como open source bajo los términos de [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task default: :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cuitar"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -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,26 @@
1
+ require_relative 'lib/cuitar/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'cuitar'
5
+ spec.version = Cuitar::VERSION
6
+ spec.authors = ['Sebastian Rabuini']
7
+ spec.email = ['sebas@wasabit.com.ar']
8
+
9
+ spec.summary = 'Valida y formatea CUIT argentinas.'
10
+ spec.description = 'Valida y formatea CUIT argentinas.'
11
+ spec.homepage = 'https://github.com/srabuini/cuitar'
12
+ spec.license = 'MIT'
13
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
14
+
15
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
16
+
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = 'https://github.com/srabuini/cuitar'
19
+
20
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = 'exe'
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ['lib']
26
+ end
@@ -0,0 +1,42 @@
1
+ class Cuit
2
+ def initialize(cuit)
3
+ @cuit = cuit.to_s.tr('^0-9', '')
4
+ end
5
+
6
+ def to_s
7
+ [type, dni, check_digit].join('-')
8
+ end
9
+
10
+ def valid?
11
+ @cuit.size == 11 && calculated_digit == check_digit
12
+ end
13
+
14
+ private
15
+
16
+ def type
17
+ @type ||= @cuit[0, 2]
18
+ end
19
+
20
+ def dni
21
+ @dni ||= @cuit[2, 8]
22
+ end
23
+
24
+ def check_digit
25
+ @check_digit ||= @cuit[-1].to_i
26
+ end
27
+
28
+ def cuit_sequence
29
+ (type + dni).chars.map(&:to_i)
30
+ end
31
+
32
+ def calculated_digit
33
+ sequence = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2]
34
+ sum = sequence
35
+ .zip(cuit_sequence)
36
+ .reduce(0) { |a, e| a + e.reduce(:*) }
37
+
38
+ diff = 11 - sum % 11
39
+
40
+ diff == 11 ? 0 : diff
41
+ end
42
+ end
@@ -0,0 +1,6 @@
1
+ require 'cuitar/version'
2
+ require 'cuit'
3
+
4
+ module Cuitar
5
+ class Error < StandardError; end
6
+ end
@@ -0,0 +1,3 @@
1
+ module Cuitar
2
+ VERSION = '1.0.0'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cuitar
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Sebastian Rabuini
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2021-01-28 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Valida y formatea CUIT argentinas.
14
+ email:
15
+ - sebas@wasabit.com.ar
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - ".gitignore"
21
+ - ".travis.yml"
22
+ - Gemfile
23
+ - Gemfile.lock
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - bin/console
28
+ - bin/setup
29
+ - cuitar.gemspec
30
+ - lib/cuit.rb
31
+ - lib/cuitar.rb
32
+ - lib/cuitar/version.rb
33
+ homepage: https://github.com/srabuini/cuitar
34
+ licenses:
35
+ - MIT
36
+ metadata:
37
+ homepage_uri: https://github.com/srabuini/cuitar
38
+ source_code_uri: https://github.com/srabuini/cuitar
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 2.3.0
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubygems_version: 3.0.3
55
+ signing_key:
56
+ specification_version: 4
57
+ summary: Valida y formatea CUIT argentinas.
58
+ test_files: []