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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a9b04bfd104221f20485349730896da8fea6f765
4
- data.tar.gz: 44e8aba1fd5554629beeba15eeaf656f626bd12b
3
+ metadata.gz: c0a359a7a13b1e48479ede3cab9dc6ed02692a11
4
+ data.tar.gz: 594d5bc25b465efd0e8e9c50d1eca227d52769e1
5
5
  SHA512:
6
- metadata.gz: 97d08a5f0315edc5b3e0bc247aa9196afa30e24cc01f1f337dd50cf06635758f19dc66b1dc37e8c9d29fa43b3d9a5540acef01384ca767bc34e21449b791d765
7
- data.tar.gz: 55153aba3380536ddde7198d487bffaa358ff5f7b60c5912809734111f548644d1a3bdced1415ba3187822801e2f838c8f93f6cc202040f366828d0136515c9e
6
+ metadata.gz: db76438dc98364c4f9fc88629910e44428f07cf6eb5c0305904c5ab66df0fdd117ce27f306292a9181fe573f2d66edc0b573057067c6ac79d50644b6204a3a8c
7
+ data.tar.gz: 70ca54c1394e534822c23e67cdc67fdb4cf916ebd0a6d20c68e0c2fe92cb9fd1794105c5702fe0f606273220ac0effc8f1c3f8108c4aa88f148902871dd30365
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in mxn_banks.gemspec
4
4
  gemspec
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "mxn_banks"
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 "irb"
13
+ require 'irb'
14
14
  IRB.start(__FILE__)
data/lib/mxn_banks.rb CHANGED
@@ -1,4 +1,4 @@
1
- require "mxn_banks/version"
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
@@ -1,3 +1,3 @@
1
1
  module MxnBanks
2
- VERSION = "0.1.1"
2
+ VERSION = '0.1.2'.freeze
3
3
  end
data/mxn_banks.gemspec CHANGED
@@ -1,10 +1,11 @@
1
1
  # coding: utf-8
2
- lib = File.expand_path("../lib", __FILE__)
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require "mxn_banks/version"
5
+ require 'mxn_banks/version'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
- spec.name = "mxn_banks"
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.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-25 00:00:00.000000000 Z
11
+ date: 2017-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler