mxn_banks 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/Rakefile +3 -3
- data/bin/console +3 -3
- data/lib/mxn_banks.rb +20 -1
- data/lib/mxn_banks/version.rb +1 -1
- data/mxn_banks.gemspec +4 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0a359a7a13b1e48479ede3cab9dc6ed02692a11
|
4
|
+
data.tar.gz: 594d5bc25b465efd0e8e9c50d1eca227d52769e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db76438dc98364c4f9fc88629910e44428f07cf6eb5c0305904c5ab66df0fdd117ce27f306292a9181fe573f2d66edc0b573057067c6ac79d50644b6204a3a8c
|
7
|
+
data.tar.gz: 70ca54c1394e534822c23e67cdc67fdb4cf916ebd0a6d20c68e0c2fe92cb9fd1794105c5702fe0f606273220ac0effc8f1c3f8108c4aa88f148902871dd30365
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'mxn_banks'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,5 @@ require "mxn_banks"
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'irb'
|
14
14
|
IRB.start(__FILE__)
|
data/lib/mxn_banks.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'mxn_banks/version'
|
2
2
|
|
3
3
|
module MxnBanks
|
4
4
|
autoload :Bank, 'mxn_banks/bank'
|
@@ -11,4 +11,23 @@ module MxnBanks
|
|
11
11
|
json_file = File.read(File.join(File.dirname(__FILE__), 'banks.json'))
|
12
12
|
@banks ||= JSON.parse(json_file, symbolize_names: true)
|
13
13
|
end
|
14
|
+
|
15
|
+
def self.valid(clabe)
|
16
|
+
sliced_clabe = clabe.slice(0,17).split('')
|
17
|
+
w_factor = weight(sliced_clabe)
|
18
|
+
module_ten = sliced_clabe.map.with_index { |n, i| (n.to_i * w_factor[i]).modulo(10) }
|
19
|
+
clabe.slice(-1).to_i == current_control_digit(module_ten)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def self.weight(clabe)
|
25
|
+
w_factor = { 0 => 3, 1 => 7, 2 => 1 }
|
26
|
+
clabe.map.with_index { |n, i| w_factor[i.to_i.modulo(3)] }
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.current_control_digit(arr)
|
30
|
+
module_sum = arr.reduce { |sum, n| sum + n }
|
31
|
+
10 - module_sum.modulo(10)
|
32
|
+
end
|
14
33
|
end
|
data/lib/mxn_banks/version.rb
CHANGED
data/mxn_banks.gemspec
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
# coding: utf-8
|
2
|
-
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require
|
5
|
+
require 'mxn_banks/version'
|
5
6
|
|
6
7
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
8
|
+
spec.name = 'mxn_banks'
|
8
9
|
spec.version = MxnBanks::VERSION
|
9
10
|
spec.authors = ['aldosolorzano']
|
10
11
|
spec.email = ['aldosolorzanop@gmail.com']
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mxn_banks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- aldosolorzano
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-07-
|
11
|
+
date: 2017-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|