colombia_nit_dv 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: f9eabcf2b10468235370aeef5b5a38498c8d5a5841d105cc5c029ae3ff23341f
4
+ data.tar.gz: 759a0a72a93b252869d3c450c489ec4075b180d0423cf4d33d7a675179f402c8
5
+ SHA512:
6
+ metadata.gz: a4548ba6ebd4a2b86ceeb14353c9276f425671d00d817ce96aa2664f4e519eddf9d6875ffa14c9f70dc0c5be350d52bfd0505b6ca24718a85b73c5583a66a206
7
+ data.tar.gz: c7c0768fa5560b313a40264b76202908d4eb11953fe92cf8691babfabc5ddcedcd714c1c5e5d05318b2aa4e018a8c288bf0fd9350f45b9b13c1038e967da5847
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ # Changelog
2
+
3
+ Todas las versiones importantes de `colombia_nit_dv` serán documentadas aquí.
4
+
5
+ ## [0.1.0] - 2025-02-12
6
+ ### Añadido
7
+ - Primera versión pública de la gema.
8
+ - Implementación del cálculo de dígito de verificación del NIT colombiano.
9
+ - Limpieza de caracteres comunes (espacios, puntos, guiones, comas).
10
+ - Validación de NIT numérico.
11
+ - Compatibilidad con Ruby >= 2.6.
12
+ - Documentación inicial y pruebas básicas (RSpec).
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,87 @@
1
+ # Contributing Guide
2
+
3
+ ¡Gracias por tu interés en contribuir a **colombia_nit_dv**!
4
+
5
+ Este proyecto es pequeño, pero cualquier mejora es bienvenida.
6
+ Por favor sigue estas recomendaciones:
7
+
8
+ ---
9
+
10
+ ## 🛠 Requisitos
11
+
12
+ - Ruby >= 2.6
13
+ - Bundler instalado
14
+ - Git
15
+
16
+ ---
17
+
18
+ ## 📥 1. Haz un Fork del repositorio
19
+
20
+ En GitHub, presiona el botón **Fork** y crea tu propia copia del repo:
21
+
22
+ 👉 https://github.com/eduardo-m88/colombia_nit_dv
23
+
24
+ ---
25
+
26
+ ## 🌿 2. Crea una rama nueva
27
+
28
+ ```bash
29
+ git checkout -b mi-mejora
30
+ ```
31
+
32
+ Usa nombres descriptivos:
33
+
34
+ - `fix/validacion-nit`
35
+ - `feature/agregar-validador-rails`
36
+ - `chore/actualizar-readme`
37
+
38
+ ---
39
+
40
+ ## 🧪 3. Corre las pruebas
41
+
42
+ Antes de enviar cambios:
43
+
44
+ ```bash
45
+ bundle install
46
+ bundle exec rspec
47
+ ```
48
+
49
+ Si agregas nuevas funciones, añade pruebas en `spec/`.
50
+
51
+ ---
52
+
53
+ ## ✍️ 4. Haz commits claros
54
+
55
+ ```bash
56
+ git commit -m "Fix: manejo de espacios en NIT"
57
+ ```
58
+
59
+ ---
60
+
61
+ ## 🔄 5. Sube los cambios y crea un Pull Request
62
+
63
+ ```bash
64
+ git push origin mi-mejora
65
+ ```
66
+
67
+ Luego crea el **Pull Request** describiendo:
68
+
69
+ - ¿Qué problema resuelve?
70
+ - ¿Cómo lo implementaste?
71
+ - ¿Agregaste pruebas?
72
+ - ¿Hay cambios breaking?
73
+
74
+ ---
75
+
76
+ ## ✔️ Revisión
77
+
78
+ - Revisaré tu PR lo más pronto posible 🚀
79
+ - Si necesitas guía o quieres discutir una idea, abre un Issue.
80
+
81
+ ---
82
+
83
+ ## ❤️ Gracias
84
+
85
+ Cualquier aporte es valioso — desde documentación, ideas, tests, hasta mejoras de código.
86
+
87
+ ¡Gracias por ayudar a mejorar `colombia_nit_dv`!
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Eduardo Mendoza
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.
data/README.md ADDED
@@ -0,0 +1,124 @@
1
+ # Colombia NIT DV
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/colombia_nit_dv.svg)](https://badge.fury.io/rb/colombia_nit_dv)
4
+
5
+ Gema ligera para calcular el **dígito de verificación (DV)** del **NIT en Colombia**, usando el algoritmo oficial utilizado por la DIAN / RUES.
6
+
7
+ No tiene dependencias externas y funciona en Ruby **>= 2.6**.
8
+
9
+ ---
10
+
11
+ ## ✨ Características
12
+
13
+ - Calcula el dígito de verificación del NIT colombiano.
14
+ - Admite NIT con espacios, puntos, guiones o comas.
15
+ - Valida que el NIT contenga solo números.
16
+ - Compatible con Ruby 2.6+, 2.7 y 3.x.
17
+ - Sin dependencias: rápida y segura.
18
+
19
+ ---
20
+
21
+ ## 📦 Instalación
22
+
23
+ Agrega esta línea a tu `Gemfile`:
24
+
25
+ ```ruby
26
+ gem "colombia_nit_dv"
27
+ ```
28
+
29
+ Y ejecuta:
30
+
31
+ ```bash
32
+ bundle install
33
+ ```
34
+
35
+ O instálala manualmente:
36
+
37
+ ```bash
38
+ gem install colombia_nit_dv
39
+ ```
40
+
41
+ ---
42
+
43
+ ## 🧪 Uso
44
+
45
+ ```ruby
46
+ require "colombia_nit_dv"
47
+
48
+ dv = ColombiaNitDv.verification_digit("900373923")
49
+ puts dv
50
+ # => 8
51
+ ```
52
+
53
+ También funciona si el NIT viene con caracteres adicionales:
54
+
55
+ ```ruby
56
+ ColombiaNitDv.verification_digit(" 900.373.923- ")
57
+ # => 8
58
+ ```
59
+
60
+ ---
61
+
62
+ ## 📘 API
63
+
64
+ ### `ColombiaNitDv.verification_digit(nit)`
65
+
66
+ **Parámetros:**
67
+
68
+ | Parámetro | Tipo | Descripción |
69
+ |----------|--------|--------------------------------------------------|
70
+ | `nit` | String | Número de NIT con o sin formato (., -, espacios) |
71
+
72
+ **Retorna:**
73
+
74
+ - `Integer` → el dígito de verificación (0–9)
75
+ - Lanza `ArgumentError` si el NIT no es numérico
76
+
77
+ ---
78
+
79
+ ## 🧰 Ejemplo práctico en Rails
80
+
81
+ Validador personalizado:
82
+
83
+ ```ruby
84
+ validate :nit_with_dv
85
+
86
+ def nit_with_dv
87
+ expected_dv = ColombiaNitDv.verification_digit(nit)
88
+ errors.add(:dv, "no coincide") if dv.to_i != expected_dv
89
+ end
90
+ ```
91
+
92
+ ---
93
+
94
+ ## 🧪 Pruebas
95
+
96
+ Para ejecutar los tests:
97
+
98
+ ```bash
99
+ bundle exec rspec
100
+ ```
101
+
102
+ ---
103
+
104
+ ## 🤝 Contribuciones
105
+
106
+ ¡Las contribuciones son bienvenidas!
107
+
108
+ 1. Haz un fork del proyecto
109
+ 2. Crea una rama: `git checkout -b mi-mejora`
110
+ 3. Envía un PR
111
+
112
+ ---
113
+
114
+ ## 📄 Licencia
115
+
116
+ Este proyecto está disponible bajo la licencia **MIT**.
117
+
118
+ ---
119
+
120
+ ## 📬 Autor
121
+
122
+ **Eduardo Mendoza**
123
+ GitHub: https://github.com/eduardo-m88
124
+ Email: eduardoalfonsom88@gmail.com
data/Rakefile ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ task default: %i[]
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ColombiaNitDv
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,31 @@
1
+ require "colombia_nit_dv/version"
2
+
3
+ module ColombiaNitDv
4
+ module_function
5
+
6
+ # Calcula el dígito de verificación de un NIT en Colombia
7
+ def verification_digit(nit)
8
+ my_nit = nit.to_s.gsub(/[\s,.\-]/, "")
9
+
10
+ unless my_nit.match?(/\A\d+\z/)
11
+ raise ArgumentError, "El nit/cédula '#{my_nit}' no es válido(a). Debe ser numérico."
12
+ end
13
+
14
+ vpri = {
15
+ 1 => 3, 2 => 7, 3 => 13, 4 => 17, 5 => 19,
16
+ 6 => 23, 7 => 29, 8 => 37, 9 => 41, 10 => 43,
17
+ 11 => 47, 12 => 53, 13 => 59, 14 => 67, 15 => 71
18
+ }
19
+
20
+ x = 0
21
+ z = my_nit.length
22
+
23
+ (0...z).each do |i|
24
+ y = my_nit[i].to_i
25
+ x += y * vpri[z - i]
26
+ end
27
+
28
+ y = x % 11
29
+ (y > 1) ? 11 - y : y
30
+ end
31
+ end
@@ -0,0 +1,4 @@
1
+ module ColombiaNitDv
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: colombia_nit_dv
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Eduardo Mendoza
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2025-11-12 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Gema ligera y sin dependencias que implementa el algoritmo oficial usado
14
+ por DIAN/RUES para calcular el dígito de verificación (DV) del NIT en Colombia.
15
+ email:
16
+ - eduardoalfonsom88@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".rspec"
22
+ - CHANGELOG.md
23
+ - CONTRIBUTING.md
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - lib/colombia_nit_dv.rb
28
+ - lib/colombia_nit_dv/version.rb
29
+ - sig/colombia_nit_dv.rbs
30
+ homepage: https://github.com/eduardo-m88/colombia_nit_dv
31
+ licenses:
32
+ - MIT
33
+ metadata:
34
+ homepage_uri: https://github.com/eduardo-m88/colombia_nit_dv
35
+ source_code_uri: https://github.com/eduardo-m88/colombia_nit_dv
36
+ changelog_uri: https://github.com/eduardo-m88/colombia_nit_dv/blob/main/CHANGELOG.md
37
+ allowed_push_host: https://rubygems.org
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '2.6'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '0'
52
+ requirements: []
53
+ rubygems_version: 3.5.11
54
+ signing_key:
55
+ specification_version: 4
56
+ summary: Calcula el dígito de verificación del NIT colombiano.
57
+ test_files: []