bitan 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/bitan.rb +31 -4
  2. data/lib/bitan/version.rb +1 -1
  3. metadata +1 -1
@@ -1,7 +1,34 @@
1
1
  require "bitan/version"
2
2
 
3
- module Bitan
4
- def is_ruby_awesome?
5
- "Yes"
6
- end
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 => '30', :X => '31',
12
+ :Y => '32', :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
+
30
+ return sum % 10 == 0
7
31
  end
32
+
33
+ end
34
+ puts 'a123456789'.is_valid_taiwanese_id?
@@ -1,3 +1,3 @@
1
1
  module Bitan
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: bitan
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: