taiwanese_id_builder 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8591274c30e848ae34cf0b9d4ec2f06de1bea159
4
+ data.tar.gz: 255e3b799d21fb6a50a12475a36babb8e6f3e052
5
+ SHA512:
6
+ metadata.gz: b69c691a61696c37cdeac7828118442eab256ecc644191b4280a718c3c705b54588d6887d7c7d407a05997a326aa16f64dd0e8fc0c234a586d05810edbed0219
7
+ data.tar.gz: bf0eb10a70e8e458c3f3e23a173997438453e180570b66bcf01ffa092a334f9336938d81ddc27ba68764818874cd4dae30b4d9872c82092f7a56277c5697ce14
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 Wayne
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+
8
+ Bundler::GemHelper.install_tasks
9
+
@@ -0,0 +1,3 @@
1
+ module TaiwaneseIdBuilder
2
+ VERSION = "0.0.3"
3
+ end
@@ -0,0 +1,56 @@
1
+ module TaiwaneseIdBuilder
2
+
3
+ TWID_LETTER = {
4
+ "A" => 10, "B" => 11, "C" => 12, "D" => 13,
5
+ "E" => 14, "F" => 15, "G" => 16, "H" => 17,
6
+ "I" => 34, "J" => 18, "K" => 19, "L" => 20,
7
+ "M" => 21, "N" => 22, "O" => 35, "P" => 23,
8
+ "Q" => 24, "R" => 25, "S" => 26, "T" => 27,
9
+ "U" => 28, "V" => 29, "W" => 32, "X" => 30,
10
+ "Y" => 31, "Z" => 33
11
+ }
12
+
13
+ MULTIPLIER = [1,9,8,7,6,5,4,3,2,1,1].freeze
14
+
15
+ def self.generate
16
+ return "A123456789"
17
+ end
18
+
19
+ def self.valid?(twid, case_sensitive = true)
20
+
21
+ twid = twid.upcase unless case_sensitive
22
+
23
+ return false if twid.length != 10
24
+ return false if !( /[A-Z](1|2)\d{8}\z/ =~ twid )
25
+
26
+ # twid_array = twid.chars
27
+
28
+ # 拿出第一個英文字母並轉成數字
29
+ first_letter = twid[0]
30
+ other_letters = twid[1..-1]
31
+
32
+ digital_twid = TWID_LETTER[first_letter].to_s + other_letters
33
+
34
+ digits = digital_twid.chars.map(&:to_i)
35
+
36
+ weighted_sum = calculate_weighted_sum(digits)
37
+
38
+ if weighted_sum % 10 == 0
39
+ return true
40
+ else
41
+ return false
42
+ end
43
+
44
+ end
45
+
46
+ def self.calculate_weighted_sum(digits)
47
+ sum = 0
48
+ 11.times do |i|
49
+ m = digits[i] * MULTIPLIER[i]
50
+ sum += m
51
+ end
52
+ sum
53
+ end
54
+
55
+
56
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :taiwanese_id_builder do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,48 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: taiwanese_id_builder
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Wayne Chu
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-12 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Taiwanese Id Builder.
14
+ email:
15
+ - wayne.5540@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - MIT-LICENSE
21
+ - Rakefile
22
+ - lib/taiwanese_id_builder.rb
23
+ - lib/taiwanese_id_builder/version.rb
24
+ - lib/tasks/taiwanese_id_builder_tasks.rake
25
+ homepage: https://github.com/wayne5540/taiwanese_id_builder
26
+ licenses: []
27
+ metadata: {}
28
+ post_install_message:
29
+ rdoc_options: []
30
+ require_paths:
31
+ - lib
32
+ required_ruby_version: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ requirements: []
43
+ rubyforge_project:
44
+ rubygems_version: 2.2.2
45
+ signing_key:
46
+ specification_version: 4
47
+ summary: Taiwanese Id Builder
48
+ test_files: []