identitycode 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: d0abbca12ef7f4e0b66b94337365ae1cc549635e
4
+ data.tar.gz: f58e83b7344b0a3119575b97bf05a0aff83cfcf7
5
+ SHA512:
6
+ metadata.gz: d1e9f42fcd99876446d2c7d76bcbc6ea0d914561f0b9991cc378108b786a4a15ddd0e8774fcf5b8a0cece391e1550311f8ea471847132387edde6ef3e3e55eda
7
+ data.tar.gz: 29d024d617b2db4da1b1edcc72a5c5338644680936c5dbd25a58e8eede8de351fbbb0f8511b16794b4a6f0651a8795d56f98a8259ef3bcad626dd0faadafaa9a
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/
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in identitycode.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Artem Pakk
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,47 @@
1
+ # IdentityCode
2
+
3
+ ## Installation
4
+
5
+ Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'identitycode'
9
+ ```
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install identitycode
18
+
19
+ ## Usage
20
+
21
+ ```ruby
22
+ > require 'identity_code'
23
+ > code = IdentityCode::Isikukood.new('38312203720')
24
+ > code.valid?
25
+ => true
26
+ > code.sex
27
+ => 'M'
28
+ > code.birth_date.to_s
29
+ => '1983-12-20'
30
+ > code.age
31
+ => 31
32
+ ```
33
+
34
+ ## Development
35
+
36
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
37
+
38
+ 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).
39
+
40
+ ## Contributing
41
+
42
+ Bug reports and pull requests are welcome on GitHub at https://github.com/defeed/identitycode. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
43
+
44
+
45
+ ## License
46
+
47
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'identity_code'
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
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'identity_code/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "identitycode"
8
+ spec.version = IdentityCode::VERSION
9
+ spec.authors = ["Artem Pakk"]
10
+ spec.email = ["apakk@me.com"]
11
+
12
+ spec.summary = %q{Ruby gem to generate and validate Estonian identity codes}
13
+ spec.description = %q{Ruby gem to generate and validate Estonian identity codes}
14
+ spec.homepage = "https://github.com/defeed/identitycode"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
@@ -0,0 +1,3 @@
1
+ module IdentityCode
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,71 @@
1
+ require 'identity_code/version'
2
+ require 'date'
3
+
4
+ module IdentityCode
5
+ class Isikukood
6
+ attr_reader :code
7
+
8
+ def initialize(code)
9
+ @code = code.to_s
10
+ end
11
+
12
+ def valid?
13
+ code.length == 11 &&
14
+ code[10].chr.to_i == control_code
15
+ end
16
+
17
+ def birth_date
18
+ return unless valid?
19
+ year = century + code[1..2].to_i
20
+ month = code[3..4].to_i
21
+ day = code[5..6].to_i
22
+ return unless Date.valid_date?(year, month, day)
23
+ Date.new(year, month, day)
24
+ end
25
+
26
+ def age
27
+ return unless valid?
28
+ now = Time.now.utc.to_date
29
+ now.year - (birth_date.year + age_correction)
30
+ end
31
+
32
+ def sex
33
+ return unless valid?
34
+ code[0].to_i.odd? ? 'M' : 'F'
35
+ end
36
+
37
+ private
38
+
39
+ def control_code
40
+ scales1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1]
41
+ checknum = scales1.each_with_index.map do |scale, i|
42
+ code[i].chr.to_i * scale
43
+ end.inject(0, :+) % 11
44
+ return checknum unless checknum == 10
45
+
46
+ scales2 = [3, 4, 5, 6, 7, 8, 9, 1, 2, 3]
47
+ checknum = scales2.each_with_index.map do |scale, i|
48
+ code[i].chr.to_i * scale
49
+ end.inject(0, :+) % 11
50
+
51
+ checknum == 10 ? 0 : checknum
52
+ end
53
+
54
+ def age_correction
55
+ now = Time.now.utc.to_date
56
+ return 0 if now.month > birth_date.month
57
+ return 0 if now.month == birth_date.month && now.day >= birth_date.day
58
+ 1
59
+ end
60
+
61
+ def century
62
+ case code[0].chr.to_i
63
+ when 1..2 then 1800
64
+ when 3..4 then 1900
65
+ when 5..6 then 2000
66
+ else
67
+ 2100
68
+ end
69
+ end
70
+ end
71
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: identitycode
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Artem Pakk
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-18 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: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
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
+ description: Ruby gem to generate and validate Estonian identity codes
42
+ email:
43
+ - apakk@me.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - CODE_OF_CONDUCT.md
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/console
55
+ - bin/setup
56
+ - identitycode.gemspec
57
+ - lib/identity_code.rb
58
+ - lib/identity_code/version.rb
59
+ homepage: https://github.com/defeed/identitycode
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.4.8
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Ruby gem to generate and validate Estonian identity codes
83
+ test_files: []