takami2 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/takami2.rb +30 -0
  2. data/lib/takami2/version.rb +1 -1
  3. metadata +1 -1
data/lib/takami2.rb CHANGED
@@ -1,5 +1,35 @@
1
1
  require "takami2/version"
2
2
 
3
+ class String
4
+ def is_valid_taiwanese_id?
5
+ cities = {
6
+ :A => '10', :B => '11', :C => '12', :D => '13',
7
+ :E => '14', :F => '15', :G => '16', :H => '17',
8
+ :I => '34', :J => '18', :K => '19', :L => '20',
9
+ :M => '21', :N => '22', :O => '35', :P => '23',
10
+ :Q => '24', :R => '25', :S => '26', :T => '27',
11
+ :U => '28', :V => '29', :W => '32', :X => '30',
12
+ :Y => '31', :Z => '33',
13
+ }
14
+
15
+ id_array = self.upcase.split('')
16
+
17
+ special = cities[id_array.first.to_sym][0].to_i * 1 + cities[id_array.first.to_sym][1].to_i * 9
18
+ sum =
19
+ special +
20
+ id_array[1].to_i * 8 +
21
+ id_array[2].to_i * 7 +
22
+ id_array[3].to_i * 6 +
23
+ id_array[4].to_i * 5 +
24
+ id_array[5].to_i * 4 +
25
+ id_array[6].to_i * 3 +
26
+ id_array[7].to_i * 2 +
27
+ id_array[8].to_i * 1 +
28
+ id_array[9].to_i
29
+ return sum % 10 == 0
30
+ end
31
+ end
32
+
3
33
  module Takami2
4
34
  def is_ruby_awesome?
5
35
  "YES"
@@ -1,3 +1,3 @@
1
1
  module Takami2
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: takami2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: