codecal 0.3.0 → 0.3.1
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 +4 -4
- data/README.md +7 -1
- data/lib/code.rb +4 -0
- data/lib/codecal/version.rb +1 -1
- data/lib/codecal.rb +11 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 45057d12f1a5354a04806e2ad76421aeda89f257
|
4
|
+
data.tar.gz: 53f3855f2210928a72621d6ed2ce4b86715bedee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e60a6a6d8f3d78f50918ad7dacdd7fe646da6eb9a1e5c05c3cba17978f33bea36d3edd03161f92e08ccdae13b359b4e03e4d304c242b1604720708bc3d66733
|
7
|
+
data.tar.gz: b864f38e05f08544000bc4fd7ae137492bb5c9686b66cfbc898af5f1378c3ef8959309ab42a55a567a74b88edfd0dbeea4ed59a1d9e5c298b369f622f5208396
|
data/README.md
CHANGED
@@ -33,6 +33,12 @@ Codecal.bank_customer_code_generate(account_id, currency)
|
|
33
33
|
# Parameters:
|
34
34
|
# customer_code : String
|
35
35
|
# Return:
|
36
|
-
# boolean
|
36
|
+
# valid : boolean
|
37
37
|
Codecal.validate_bank_customer_code(String)
|
38
38
|
|
39
|
+
# Get currency name
|
40
|
+
# Parameters:
|
41
|
+
# currency_code : String(4)
|
42
|
+
# Return:
|
43
|
+
# currency name : String -- nil if not found
|
44
|
+
Codecal.get_currency_name(String)
|
data/lib/code.rb
CHANGED
data/lib/codecal/version.rb
CHANGED
data/lib/codecal.rb
CHANGED
@@ -6,6 +6,10 @@ module Codecal
|
|
6
6
|
class<<self
|
7
7
|
def bank_customer_code_generate(account_id, currency)
|
8
8
|
errormsg = ""
|
9
|
+
if account_id == nil || currency == nil
|
10
|
+
errormsg += "parameter is nil. "
|
11
|
+
return {success:false, error: errormsg}
|
12
|
+
end
|
9
13
|
errormsg += "parameter 1 type should be Integer and length not longer than 9. " unless account_id.is_a?(Integer) && account_id.to_s.size <= 9
|
10
14
|
currency.is_a?(String) ? currency.upcase! : errormsg += "parameter 2 type should be String. "
|
11
15
|
currency_code = Code.new[currency]
|
@@ -19,15 +23,20 @@ module Codecal
|
|
19
23
|
end
|
20
24
|
|
21
25
|
def validate_bank_customer_code(customer_code)
|
22
|
-
return false unless customer_code.is_a?(String) && customer_code.size == 16
|
26
|
+
return false unless customer_code && customer_code.is_a?(String) && customer_code.size == 16
|
23
27
|
calcode = code_calculate(customer_code[0..12].split("").map! {|i| i.to_i}, @@generate_seed)
|
24
28
|
return customer_code == calcode
|
25
29
|
end
|
26
30
|
|
31
|
+
def get_currency_name(currency_code)
|
32
|
+
return nil if !currency_code || currency_code.size !=4 || !currency_code.is_a?(String)
|
33
|
+
return Code.new.get_name(currency_code)
|
34
|
+
end
|
35
|
+
|
27
36
|
private
|
28
37
|
def code_calculate(array, seed)
|
29
38
|
code = array.each_with_index.inject(0){|count, (i, index)| count += i*seed[index]}
|
30
39
|
return array.join + ("%03d" % code).to_s
|
31
40
|
end
|
32
41
|
end
|
33
|
-
end
|
42
|
+
end
|