demotoy 0.0.2 → 0.0.3
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.
- data/lib/demotoy.rb +32 -0
- data/lib/demotoy/version.rb +1 -1
- metadata +1 -1
data/lib/demotoy.rb
CHANGED
|
@@ -4,3 +4,35 @@ module Demotoy
|
|
|
4
4
|
def who_is_your_daddy?
|
|
5
5
|
puts "my papa"
|
|
6
6
|
end
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def is_valid_taiwanese_id?(id)
|
|
10
|
+
cities = {
|
|
11
|
+
:A => '10', :B => '11', :C => '12', :D => '13',
|
|
12
|
+
:E => '14', :F => '15', :G => '16', :H => '17',
|
|
13
|
+
:I => '34', :J => '18', :K => '19', :L => '20',
|
|
14
|
+
:M => '21', :N => '22', :O => '35', :P => '23',
|
|
15
|
+
:Q => '24', :R => '25', :S => '26', :T => '27',
|
|
16
|
+
:U => '28', :V => '29', :W => '32', :X => '30',
|
|
17
|
+
:Y => '31', :Z => '33',
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
id_array = id.upcase.split('')
|
|
21
|
+
|
|
22
|
+
special = cities[id_array.first.to_sym][0].to_i + cities[id_array.first.to_sym][1].to_i * 9
|
|
23
|
+
sum =
|
|
24
|
+
special +
|
|
25
|
+
id_array[1].to_i * 8 +
|
|
26
|
+
id_array[2].to_i * 7 +
|
|
27
|
+
id_array[3].to_i * 6 +
|
|
28
|
+
id_array[4].to_i * 5 +
|
|
29
|
+
id_array[5].to_i * 4 +
|
|
30
|
+
id_array[6].to_i * 3 +
|
|
31
|
+
id_array[7].to_i * 2 +
|
|
32
|
+
id_array[8].to_i * 1 +
|
|
33
|
+
id_array[9].to_i
|
|
34
|
+
|
|
35
|
+
return sum % 10 == 0
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
puts is_valid_taiwanese_id?('a123456789')
|
data/lib/demotoy/version.rb
CHANGED