argentinian-validations 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 634fc956d71ac0288d5fc3d1709bc4f1dc9ccfc1c48ee4060f756a4c8f30117e
4
+ data.tar.gz: d77a5adda336e4cbf80feb5055ace11d58bfc99d456ccc3934a4f4e3219202f5
5
+ SHA512:
6
+ metadata.gz: ba1ba81138c18be022562a1e1d42dc326d0d0a3748ec71b8e58fe20bd931e71144e87054866fbadd4db876c766bf303c7858f78541c8375e5a3d258814c3e20d
7
+ data.tar.gz: 3b8936e9598e368b58c22128f14ff87b2166b2d16065750e740c8fe25edecaa8f5c96d03f852195982c97856447c919fa89f4604fe4a11a844a8476891058d8a
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --require 'spec_helper'
3
+
@@ -0,0 +1,20 @@
1
+ require:
2
+ - rubocop-rspec
3
+ - rubocop-rails
4
+ - rubocop-performance
5
+
6
+ Documentation:
7
+ Enabled: false
8
+
9
+ LineLength:
10
+ Max: 99
11
+
12
+ FrozenStringLiteralComment:
13
+ Enabled: false
14
+
15
+ Style/DoubleNegation:
16
+ Enabled: false
17
+
18
+ Metrics/BlockLength:
19
+ Exclude:
20
+ - spec/**/*
@@ -0,0 +1,29 @@
1
+ env:
2
+ global:
3
+ - CC_TEST_REPORTER_ID=86b6df4bcfa62c8e9c14d57182fa0a75444e11c397dc1f8571f2dfa8fe5f0227
4
+
5
+ language: ruby
6
+ rvm:
7
+ - 2.3.0
8
+ - 2.4.0
9
+ - 2.5.0
10
+ - 2.6.0
11
+
12
+ install:
13
+ - gem install bundler -v 1.17.3
14
+ - bundle install --retry=3
15
+
16
+ before_script:
17
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
18
+ - chmod +x ./cc-test-reporter
19
+ - ./cc-test-reporter before-build
20
+
21
+ script:
22
+ - bundle exec rspec
23
+ - bundle exec rubocop Gemfile lib spec
24
+
25
+ after_script:
26
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
27
+
28
+ os:
29
+ - linux
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in argentinian-validations.gemspec
4
+ gemspec
5
+
6
+ group :development, :test do
7
+ gem 'byebug', '~> 11.0'
8
+ end
9
+
10
+ group :test do
11
+ gem 'rspec', '~> 3.8'
12
+ gem 'rubocop', '~> 0.74'
13
+ gem 'rubocop-performance', '~> 1.4'
14
+ gem 'rubocop-rails', '~> 2.3'
15
+ gem 'rubocop-rspec', '~> 1.35'
16
+ gem 'simplecov', '~> 0.17.1'
17
+ end
@@ -0,0 +1,72 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ argentinian-validations (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.0)
10
+ byebug (11.0.1)
11
+ diff-lcs (1.3)
12
+ docile (1.3.2)
13
+ jaro_winkler (1.5.3)
14
+ json (2.2.0)
15
+ parallel (1.18.0)
16
+ parser (2.6.5.0)
17
+ ast (~> 2.4.0)
18
+ rack (2.0.7)
19
+ rainbow (3.0.0)
20
+ rake (10.5.0)
21
+ rspec (3.9.0)
22
+ rspec-core (~> 3.9.0)
23
+ rspec-expectations (~> 3.9.0)
24
+ rspec-mocks (~> 3.9.0)
25
+ rspec-core (3.9.0)
26
+ rspec-support (~> 3.9.0)
27
+ rspec-expectations (3.9.0)
28
+ diff-lcs (>= 1.2.0, < 2.0)
29
+ rspec-support (~> 3.9.0)
30
+ rspec-mocks (3.9.0)
31
+ diff-lcs (>= 1.2.0, < 2.0)
32
+ rspec-support (~> 3.9.0)
33
+ rspec-support (3.9.0)
34
+ rubocop (0.75.1)
35
+ jaro_winkler (~> 1.5.1)
36
+ parallel (~> 1.10)
37
+ parser (>= 2.6)
38
+ rainbow (>= 2.2.2, < 4.0)
39
+ ruby-progressbar (~> 1.7)
40
+ unicode-display_width (>= 1.4.0, < 1.7)
41
+ rubocop-performance (1.5.0)
42
+ rubocop (>= 0.71.0)
43
+ rubocop-rails (2.3.2)
44
+ rack (>= 1.1)
45
+ rubocop (>= 0.72.0)
46
+ rubocop-rspec (1.36.0)
47
+ rubocop (>= 0.68.1)
48
+ ruby-progressbar (1.10.1)
49
+ simplecov (0.17.1)
50
+ docile (~> 1.1)
51
+ json (>= 1.8, < 3)
52
+ simplecov-html (~> 0.10.0)
53
+ simplecov-html (0.10.2)
54
+ unicode-display_width (1.6.0)
55
+
56
+ PLATFORMS
57
+ ruby
58
+
59
+ DEPENDENCIES
60
+ argentinian-validations!
61
+ bundler (~> 1.17)
62
+ byebug (~> 11.0)
63
+ rake (~> 10.0)
64
+ rspec (~> 3.8)
65
+ rubocop (~> 0.74)
66
+ rubocop-performance (~> 1.4)
67
+ rubocop-rails (~> 2.3)
68
+ rubocop-rspec (~> 1.35)
69
+ simplecov (~> 0.17.1)
70
+
71
+ BUNDLED WITH
72
+ 1.17.3
@@ -0,0 +1,40 @@
1
+ # Argentinian::Validations
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/crf.svg)](https://badge.fury.io/rb/crf)
4
+ [![Build Status](https://travis-ci.org/alebian/argentinian-validations.svg)](https://travis-ci.org/alebian/argentinian-validations)
5
+ [![Code Climate](https://codeclimate.com/github/alebian/argentinian-validations/badges/gpa.svg)](https://codeclimate.com/github/alebian/argentinian-validations)
6
+ [![Test Coverage](https://codeclimate.com/github/alebian/argentinian-validations/badges/coverage.svg)](https://codeclimate.com/github/alebian/argentinian-validations/coverage)
7
+
8
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/argentinian/validations`. To experiment with that code, run `bin/console` for an interactive prompt.
9
+
10
+ TODO: Delete this and the text above, and describe your gem
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'argentinian-validations'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install argentinian-validations
27
+
28
+ ## Usage
29
+
30
+ TODO: Write usage instructions here
31
+
32
+ ## Development
33
+
34
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
35
+
36
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
37
+
38
+ ## Contributing
39
+
40
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/argentinian-validations.
@@ -0,0 +1,2 @@
1
+ require 'bundler/gem_tasks'
2
+ task default: :spec
@@ -0,0 +1,18 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'argentinian/validations/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'argentinian-validations'
7
+ spec.version = Argentinian::Validations::VERSION
8
+ spec.authors = ['Alejandro Bezdjian']
9
+ spec.email = ['alebezdjian@gmail.com']
10
+ spec.summary = 'Validations for Argentinian specific information'
11
+ spec.description = 'Validations for Argentinian specific information'
12
+ spec.homepage = 'https://github.com/alebian/argentinian-validations'
13
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec)/}) }
14
+ spec.require_paths = ['lib']
15
+
16
+ spec.add_development_dependency 'bundler', '~> 1.17'
17
+ spec.add_development_dependency 'rake', '~> 10.0'
18
+ end
@@ -0,0 +1,10 @@
1
+ require 'argentinian/validations/version'
2
+ require 'argentinian/validations/base'
3
+ require 'argentinian/validations/cbu'
4
+ require 'argentinian/validations/cuil'
5
+ require 'argentinian/validations/cuit'
6
+
7
+ module Argentinian
8
+ module Validations
9
+ end
10
+ end
@@ -0,0 +1,55 @@
1
+ module Argentinian
2
+ module Validations
3
+ class Base
4
+ class NotNumericError < StandardError; end
5
+ class LengthError < StandardError; end
6
+
7
+ attr_reader :value, :errors
8
+
9
+ def initialize(value)
10
+ @value = value.to_s
11
+ @errors = []
12
+ end
13
+
14
+ def valid?
15
+ raise 'Subclass must implement'
16
+ end
17
+
18
+ def validate!
19
+ raise 'Subclass must implement'
20
+ end
21
+
22
+ private
23
+
24
+ def numeric?
25
+ !!Float(@value)
26
+ rescue ArgumentError
27
+ @errors << 'Value is not numeric'
28
+ false
29
+ end
30
+
31
+ def correct_length?(length)
32
+ correct = @value.length == length
33
+ @errors << "Value length must be #{length} characters" unless correct
34
+ correct
35
+ end
36
+
37
+ def string_to_int_array(string)
38
+ string.split(//).map(&:to_i)
39
+ end
40
+
41
+ def multiply_each_element(array1, array2)
42
+ array1.zip(array2).map { |a| a.reduce(:*) }
43
+ end
44
+
45
+ def checksum_mod(checksum, value)
46
+ value - (checksum % value)
47
+ end
48
+
49
+ def sum_each_element(array)
50
+ # Some Ruby versions do not have the method `sum` in the Enumerable module
51
+ array.inject(0) { |sum, element| sum + element }
52
+ end
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,48 @@
1
+ module Argentinian
2
+ module Validations
3
+ class Cbu < Base
4
+ class BankError < StandardError; end
5
+ class AccountError < StandardError; end
6
+
7
+ def valid?
8
+ numeric? && correct_length?(22) && correct_bank? && correct_account?
9
+ end
10
+
11
+ def validate!
12
+ raise NotNumericError unless numeric?
13
+ raise LengthError unless correct_length?(22)
14
+ raise BankError unless correct_bank?
15
+ raise AccountError unless correct_account?
16
+
17
+ @value
18
+ end
19
+
20
+ private
21
+
22
+ def correct_bank?
23
+ correct = validate_block(@value[0..6], [7, 1, 3, 9, 7, 1, 3], @value[7])
24
+ @errors << 'Bank is invalid' unless correct
25
+ correct
26
+ end
27
+
28
+ def correct_account?
29
+ correct = validate_block(
30
+ @value[8..20], [3, 9, 7, 1, 3, 9, 7, 1, 3, 9, 7, 1, 3], @value[21]
31
+ )
32
+ @errors << 'Account is invalid' unless correct
33
+ correct
34
+ end
35
+
36
+ def validate_block(block, multipliers, validation)
37
+ block = string_to_int_array(block)
38
+ checksum = sum_each_element(multiply_each_element(block, multipliers))
39
+
40
+ if validation.to_i.zero?
41
+ checksum_mod(checksum, 10) == 10
42
+ else
43
+ validation.to_i == checksum_mod(checksum, 10)
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,40 @@
1
+ module Argentinian
2
+ module Validations
3
+ class Cuil < Base
4
+ class InvalidNumberError < StandardError; end
5
+
6
+ def valid?
7
+ numeric? && correct_length?(11) && correct_number?
8
+ end
9
+
10
+ def validate!
11
+ raise NotNumericError unless numeric?
12
+ raise LengthError unless correct_length?(11)
13
+ raise InvalidNumberError unless correct_number?
14
+
15
+ @value
16
+ end
17
+
18
+ private
19
+
20
+ def correct_number?
21
+ correct = validate_block!(@value[0..-2], [5, 4, 3, 2, 7, 6, 5, 4, 3, 2], @value[-1])
22
+ @errors << 'CUIT is invalid' unless correct
23
+ correct
24
+ end
25
+
26
+ def validate_block!(block, multipliers, validation)
27
+ block = string_to_int_array(block)
28
+ checksum = checksum_mod(sum_each_element(multiply_each_element(block, multipliers)), 11)
29
+
30
+ if checksum == 11
31
+ checksum = 0
32
+ elsif checksum == 10
33
+ raise InvalidNumberError
34
+ end
35
+
36
+ validation.to_i == checksum
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,6 @@
1
+ module Argentinian
2
+ module Validations
3
+ class Cuit < Cuil
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Argentinian
2
+ module Validations
3
+ VERSION = '0.1.0'.freeze
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: argentinian-validations
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alejandro Bezdjian
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-10-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.17'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.17'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Validations for Argentinian specific information
42
+ email:
43
+ - alebezdjian@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".rspec"
50
+ - ".rubocop.yml"
51
+ - ".travis.yml"
52
+ - Gemfile
53
+ - Gemfile.lock
54
+ - README.md
55
+ - Rakefile
56
+ - argentinian-validations.gemspec
57
+ - lib/argentinian/validations.rb
58
+ - lib/argentinian/validations/base.rb
59
+ - lib/argentinian/validations/cbu.rb
60
+ - lib/argentinian/validations/cuil.rb
61
+ - lib/argentinian/validations/cuit.rb
62
+ - lib/argentinian/validations/version.rb
63
+ homepage: https://github.com/alebian/argentinian-validations
64
+ licenses: []
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubygems_version: 3.0.3
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Validations for Argentinian specific information
85
+ test_files: []