tsubaki 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 438a3bebdf33a8da3029f074277a33eff23c3fbf
4
+ data.tar.gz: 9236d963e34ed6bee3f0c98e4e18b16968754ef2
5
+ SHA512:
6
+ metadata.gz: 37e45a605acd1e60b9f9ddc2e9c43b92f0c82fbc9ba99f84b7835b4fdccd4086ad8c23b36de8750d353e17133dcef5ac33f4e49a6c0d880b82e582c860a8e5ce
7
+ data.tar.gz: 32d29af3cea9e9569070f011883910f140537d7d9ef7879ca45eef3e691bb013693c525d02f01ce947d0d082087fe8cb366534b2575a8cabe7aecafe1977652e
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,16 @@
1
+ inherit_from: '.rubocop_todo.yml'
2
+
3
+ Style/AsciiComments:
4
+ Enabled: false
5
+
6
+ Style/BlockDelimiters:
7
+ Enabled: false
8
+
9
+ Style/Documentation:
10
+ Enabled: false
11
+
12
+ Style/DoubleNegation:
13
+ Enabled: false
14
+
15
+ Metrics/AbcSize:
16
+ Max: 18
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,13 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2015-10-08 20:59:18 +0900 using RuboCop version 0.34.2.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 4
10
+ # Configuration parameters: AllowURI, URISchemes.
11
+ Metrics/LineLength:
12
+ Max: 104
13
+
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.5
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in tsubaki.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,14 @@
1
+ guard :rspec, cmd: 'bundle exec rspec', failed_mode: :focus do
2
+ watch(%r{^spec/.+_spec\.rb$})
3
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch('spec/spec_helper.rb') { 'spec' }
5
+ end
6
+
7
+ guard :bundler do
8
+ watch('Gemfile')
9
+ watch(/^.+\.gemspec/)
10
+ end
11
+
12
+ guard :rubocop, all_on_start: true, cli: ['-D', '--format', 'clang'] do
13
+ watch(/.+\.rb$/)
14
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 kakipo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # Tsubaki
2
+
3
+ [![Circle CI](https://circleci.com/gh/kakipo/tsubaki/tree/master.svg?style=svg)](https://circleci.com/gh/kakipo/tsubaki/tree/master)
4
+
5
+ Each resident in Japan will be notified of his or her own Individual Number (a.k.a. "My Number") beginning in October 2015.
6
+
7
+ A My Number consists of 12 digits & the last digit is used as a check digit.
8
+ This gem provides My Number validator which inspects the format and (optionally) the check digit.
9
+
10
+ (We plan to implement other social security related code validators such as a basic pension number validator later.)
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'tsubaki'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install tsubaki
27
+
28
+ ## Usage
29
+
30
+ Add the following to your model:
31
+
32
+ ```ruby
33
+ validates :my_number, my_number: true
34
+ ```
35
+
36
+ ## Verify the check digit
37
+
38
+ In order to have stricter validation which verifies the check digit, enable strict mode.
39
+
40
+ ```ruby
41
+ validates :my_number, my_number: { strict: true }
42
+ ```
43
+
44
+ See: [行政手続における特定の個人を識別するための番号の利用等に関する法律の規定による通知カード及び個人番号カード並びに情報提供ネットワークシステムによる特定個人情報の提供等に関する省令](http://law.e-gov.go.jp/announce/H26F11001000085.html)
45
+
46
+ ## Divider
47
+
48
+ If a My Number contains any dividers, specify it.
49
+
50
+ ```ruby
51
+ # 1111-2222-3333-4444 should be valid
52
+ validates :my_number, my_number: { divider: '-' }
53
+ ```
54
+
55
+ ## Goodies
56
+
57
+ You can obtain a random yet having right check digit My Number.
58
+ This is useful when creating dummy records.
59
+
60
+ ```ruby
61
+ Tsubaki::MyNumber.rand # => 765895492872
62
+ ```
63
+
64
+ ## Development
65
+
66
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
67
+
68
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
69
+
70
+ ## Contributing
71
+
72
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kakipo/tsubaki.
73
+
74
+
75
+ ## License
76
+
77
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
78
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'tsubaki'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/circle.yml ADDED
@@ -0,0 +1,7 @@
1
+ machine:
2
+ timezone:
3
+ Asia/Tokyo
4
+
5
+ test:
6
+ pre:
7
+ - bundle exec rubocop --display-cop-names
@@ -0,0 +1,46 @@
1
+ module Tsubaki
2
+ class MyNumber
3
+ def self.rand
4
+ digits = 11.times.map { Kernel.rand(10) }.join
5
+ check_digit = calc_check_digit(digits)
6
+ "#{digits}#{check_digit}"
7
+ end
8
+
9
+ def self.calc_check_digit(digits)
10
+ fail 'must be a 11 digit number' unless digits =~ /\A\d{11}\z/
11
+
12
+ arr = digits.chars.map(&:to_i).reverse!
13
+ rem = (1..11).inject(0) do |sum, n|
14
+ pn = arr[n - 1]
15
+ qn = (n <= 6) ? (n + 1) : (n - 5)
16
+ sum + pn * qn
17
+ end % 11
18
+
19
+ rem <= 1 ? 0 : (11 - rem)
20
+ end
21
+
22
+ def initialize(digits, options = {})
23
+ @digits = digits.to_s.freeze
24
+ @options = options
25
+ end
26
+
27
+ def valid?
28
+ @options[:strict] ? valid_check_digit? : valid_pattern?
29
+ end
30
+
31
+ def valid_pattern?
32
+ !!(plain_digits =~ /\A\d{12}\z/)
33
+ end
34
+
35
+ def valid_check_digit?
36
+ return false unless valid_pattern?
37
+ plain_digits[-1].to_i == self.class.calc_check_digit(plain_digits[0, 11]).to_i
38
+ end
39
+
40
+ private
41
+
42
+ def plain_digits
43
+ @plain_digits ||= @digits.split(@options[:divider]).join('')
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,13 @@
1
+ require 'active_model'
2
+ require 'active_model/validator'
3
+
4
+ module Tsubaki
5
+ class MyNumberValidator < ActiveModel::EachValidator
6
+ def validate_each(record, attribute, value)
7
+ return if Tsubaki::MyNumber.new(value, options).valid?
8
+ record.errors[attribute] << (options[:message] || :invalid)
9
+ end
10
+ end
11
+ end
12
+
13
+ ActiveModel::Validations::MyNumberValidator = Tsubaki::MyNumberValidator
@@ -0,0 +1,3 @@
1
+ module Tsubaki
2
+ VERSION = '0.1.0'
3
+ end
data/lib/tsubaki.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'tsubaki/version'
2
+ require 'tsubaki/my_number'
3
+ require 'tsubaki/my_number_validator'
4
+
5
+ module Tsubaki
6
+ # Your code goes here...
7
+ end
data/tsubaki.gemspec ADDED
@@ -0,0 +1,40 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'tsubaki/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'tsubaki'
8
+ spec.version = Tsubaki::VERSION
9
+ spec.authors = ['kakipo']
10
+ spec.email = ['kakipo@gmail.com']
11
+
12
+ spec.summary = 'Japanese soocial security code validators.'
13
+ spec.description = 'A gem provides several social security code validators such as My Number validator, Basic Pension Number validator.'
14
+ spec.homepage = 'https://github.com/kakipo/tsubaki'
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
21
+ else
22
+ fail 'RubyGems 2.0 or newer is required to protect against public gem pushes.'
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+ spec.required_ruby_version = '>= 1.9.3'
30
+
31
+ spec.add_development_dependency 'bundler'
32
+ spec.add_development_dependency 'rake', '~> 10.0'
33
+ spec.add_development_dependency 'rspec'
34
+ spec.add_development_dependency 'guard'
35
+ spec.add_development_dependency 'guard-rspec'
36
+ spec.add_development_dependency 'guard-bundler'
37
+ spec.add_development_dependency 'guard-rubocop'
38
+
39
+ spec.add_runtime_dependency 'activemodel'
40
+ end
metadata ADDED
@@ -0,0 +1,176 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tsubaki
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - kakipo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-10-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: guard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: guard-rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: guard-bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard-rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: activemodel
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: A gem provides several social security code validators such as My Number
126
+ validator, Basic Pension Number validator.
127
+ email:
128
+ - kakipo@gmail.com
129
+ executables: []
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".gitignore"
134
+ - ".rspec"
135
+ - ".rubocop.yml"
136
+ - ".rubocop_todo.yml"
137
+ - ".travis.yml"
138
+ - Gemfile
139
+ - Guardfile
140
+ - LICENSE.txt
141
+ - README.md
142
+ - Rakefile
143
+ - bin/console
144
+ - bin/setup
145
+ - circle.yml
146
+ - lib/tsubaki.rb
147
+ - lib/tsubaki/my_number.rb
148
+ - lib/tsubaki/my_number_validator.rb
149
+ - lib/tsubaki/version.rb
150
+ - tsubaki.gemspec
151
+ homepage: https://github.com/kakipo/tsubaki
152
+ licenses:
153
+ - MIT
154
+ metadata:
155
+ allowed_push_host: https://rubygems.org
156
+ post_install_message:
157
+ rdoc_options: []
158
+ require_paths:
159
+ - lib
160
+ required_ruby_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: 1.9.3
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
166
+ requirements:
167
+ - - ">="
168
+ - !ruby/object:Gem::Version
169
+ version: '0'
170
+ requirements: []
171
+ rubyforge_project:
172
+ rubygems_version: 2.2.2
173
+ signing_key:
174
+ specification_version: 4
175
+ summary: Japanese soocial security code validators.
176
+ test_files: []