codecal 0.1.3 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 49e13158a2adfe44bda68f5fb9bee1a8053a92da
4
- data.tar.gz: 64106e9a006bfc679b9462ee7d3ce99da4136291
3
+ metadata.gz: bf8ab3809eb83ffc4cd469786d607f55a19516b5
4
+ data.tar.gz: 1bb3b3b4e0bc83055f514ba4f2469e5b8fed2961
5
5
  SHA512:
6
- metadata.gz: 378bba7168bdd2195bfe41781fc483c61095d14c3602e211dff1bc0ebffb10723a6c0c3070b680f3cd744ca6706c0d2dea7899e6aacb90697b0b20ccaf448045
7
- data.tar.gz: 902f96dd4002e78091bb07a9903459ddb8d7fba7c5988f610a012e4ab2ca888723229c094f37302cef8c271cff5fdefaa3c6803842ca69ca9dfc3eecf9fd0505
6
+ metadata.gz: d88c42d43603d68797109c7f28a66d7cd13939f33470bdf0f0bc9f70addd8b9b6928e571a162bf9fbeca882943030214488010808ecdc31def567bc93e46598c
7
+ data.tar.gz: 2b1f72a028ee35184668450fe4bc7249c3491272471292f1ba8dfa7399da98a54245242d233c55bfdb639669ba51934ecb38eebfa7312ee88b13e5767f836a4e
data/README.md CHANGED
@@ -19,6 +19,22 @@ Or install it yourself as:
19
19
  ```
20
20
  require 'codecal'
21
21
 
22
- Codecal.bank_customer_code_generate(Integer, Integer)
22
+ # Generate customer code for user account
23
+ # Parameters:
24
+ # account_id : Integer(<=9) --user account_id in acx
25
+ # currency : String --currency name
26
+ # Return:
27
+ # String(16) -- 16 numbers string
28
+ # Raise:
29
+ # pamameters type error
30
+ # currency not found
31
+ Codecal.bank_customer_code_generate(account_id, currency)
32
+
33
+ # Validate customer code
34
+ # Parameters:
35
+ # customer_code : String
36
+ # Return:
37
+ # boolean
38
+ # Return String
39
+ Codecal.validate_bank_customer_code(String)
23
40
 
24
- #return String
@@ -1,3 +1,3 @@
1
1
  module Codecal
2
- VERSION = "0.1.3"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/codecal.rb CHANGED
@@ -1,21 +1,28 @@
1
1
  require "codecal/version"
2
+ require_relative "../config/code"
2
3
 
3
4
  module Codecal
4
- def self.bank_customer_code_generate(account_id, currency)
5
- begin
6
- raise "parameter 1 type should be Integer and length less than 9" unless account_id.is_a?(Integer) && account_id.to_s.size <= 9
7
- raise "parameter 2 type should be Integer and length less than 4" unless currency.is_a?(Integer) && currency.to_s.size <= 4
8
- cal_array = ("%09d" % account_id + "%04d" % currency).split("").map! {|i| i.to_i}
9
- generate_seed = [2,7,5,3,8,9,5,9,1,6,7,3,5]
10
- return code_calculate(cal_array, generate_seed)
11
- rescue Exception => e
12
- puts e.message
5
+ @@generate_seed = [2,7,5,3,8,9,5,9,1,6,7,3,5]
6
+ class<<self
7
+ def bank_customer_code_generate(account_id, currency)
8
+ raise "parameter 1 type should be Integer and length not longer than 9" unless account_id.is_a?(Integer) && account_id.to_s.size <= 9
9
+ raise "parameter 2 type should be String" unless currency.is_a?(String)
10
+ currency_code = Code.new[currency]
11
+ raise "currency not found" unless currency_code
12
+ cal_array = ("%09d" % account_id + "%04d" % currency_code.to_i).split("").map! {|i| i.to_i}
13
+ return code_calculate(cal_array, @@generate_seed)
14
+ end
15
+
16
+ def validate_bank_customer_code(customer_code)
17
+ return false unless customer_code.is_a?(String) && customer_code.size == 16
18
+ calcode = code_calculate(customer_code[0..12].split("").map! {|i| i.to_i}, @@generate_seed)
19
+ return customer_code == calcode
13
20
  end
14
- end
15
21
 
16
- private
17
- def self.code_calculate(array, seed)
18
- code = array.each_with_index.inject(0){|count, (i, index)| count += i*seed[index]}
19
- return array.join + ("%03d" % code).to_s
22
+ private
23
+ def code_calculate(array, seed)
24
+ code = array.each_with_index.inject(0){|count, (i, index)| count += i*seed[index]}
25
+ return array.join + ("%03d" % code).to_s
26
+ end
20
27
  end
21
28
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codecal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Roger Fang
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-07 00:00:00.000000000 Z
11
+ date: 2017-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler