is_uen 0.1.0

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
+ SHA256:
3
+ metadata.gz: e5213b05265043b416745ec8cd324ae95f524e97c6de9298064888b77037edd6
4
+ data.tar.gz: 32761c20a08d9b6485ab866386bb0104f90d3f3a30b40646178b5d1a0fd5358e
5
+ SHA512:
6
+ metadata.gz: a8328e5526347500e2882442ddbe17d8d43a91e17cecab907621c2bd102600232ae1eb891b88514b145fc82e1467734e98f4d11524e95ff4d366f095409f9c24
7
+ data.tar.gz: b03bd3b4d13b42c51b998adc2c0a26c94642757190eb3907d8a0118289e80545c22b5957e0741e51aa48514e494ea79f727c2797ee50a1a890bec85c34484773
data/.rubocop.yml ADDED
@@ -0,0 +1,18 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.6
3
+ NewCops: enable
4
+ SuggestExtensions: false
5
+
6
+ Style/StringLiterals:
7
+ Enabled: true
8
+ EnforcedStyle: double_quotes
9
+
10
+ Style/StringLiteralsInInterpolation:
11
+ Enabled: true
12
+ EnforcedStyle: double_quotes
13
+
14
+ Layout/LineLength:
15
+ Max: 120
16
+
17
+ Naming/HeredocDelimiterNaming:
18
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in is_uen.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "minitest", "~> 5.0"
11
+
12
+ gem "rubocop", "~> 1.21"
data/Gemfile.lock ADDED
@@ -0,0 +1,43 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ is_uen (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.2)
10
+ minitest (5.15.0)
11
+ parallel (1.21.0)
12
+ parser (3.0.3.2)
13
+ ast (~> 2.4.1)
14
+ rainbow (3.0.0)
15
+ rake (13.0.6)
16
+ regexp_parser (2.2.0)
17
+ rexml (3.2.5)
18
+ rubocop (1.23.0)
19
+ parallel (~> 1.10)
20
+ parser (>= 3.0.0.0)
21
+ rainbow (>= 2.2.2, < 4.0)
22
+ regexp_parser (>= 1.8, < 3.0)
23
+ rexml
24
+ rubocop-ast (>= 1.12.0, < 2.0)
25
+ ruby-progressbar (~> 1.7)
26
+ unicode-display_width (>= 1.4.0, < 3.0)
27
+ rubocop-ast (1.15.0)
28
+ parser (>= 3.0.1.1)
29
+ ruby-progressbar (1.11.0)
30
+ unicode-display_width (2.1.0)
31
+
32
+ PLATFORMS
33
+ x86_64-darwin-20
34
+ x86_64-linux
35
+
36
+ DEPENDENCIES
37
+ is_uen!
38
+ minitest (~> 5.0)
39
+ rake (~> 13.0)
40
+ rubocop (~> 1.21)
41
+
42
+ BUNDLED WITH
43
+ 2.2.33
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 yaojie
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,55 @@
1
+ # IsUen
2
+
3
+ Simple gem to check whether an UEN has a valid format and date.
4
+
5
+ Format is obtained from [https://www.uen.gov.sg/ueninternet/faces/pages/admin/aboutUEN.jspx](https://www.uen.gov.sg/ueninternet/faces/pages/admin/aboutUEN.jspx), last updated/reviewed on 08 Jan 2018.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'is_uen'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install is_uen
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ IsUen.uen?('12345678A') # business? || company? || new_uen?
27
+ IsUen.business?('12345678A')
28
+ IsUen.company?('123456789A')
29
+ IsUen.new_uen?('T12GB1234X')
30
+ ```
31
+
32
+ The library also provides convenience functions to check for a specific entity type (obtain the full list [here](https://www.uen.gov.sg/ueninternet/faces/pages/admin/aboutUEN.jspx)).
33
+
34
+ ```ruby
35
+ IsUen.ll?('T12LL1234X') # returns true
36
+ IsUen.lp?('T12AA1234X') # returns false
37
+ ```
38
+
39
+ ## Development
40
+
41
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
42
+
43
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
44
+
45
+ ## Caveats
46
+
47
+ This gem does not verify the existence of UENs.
48
+
49
+ ## Contributing
50
+
51
+ Bug reports and pull requests are welcome on GitHub at https://github.com/causztic/is_uen.
52
+
53
+ ## License
54
+
55
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.libs << "lib"
9
+ t.test_files = FileList["test/**/*_test.rb"]
10
+ end
11
+
12
+ require "rubocop/rake_task"
13
+
14
+ RuboCop::RakeTask.new
15
+
16
+ task default: %i[test rubocop]
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "is_uen"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IsUen
4
+ VERSION = "0.1.0"
5
+ end
data/lib/is_uen.rb ADDED
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "is_uen/version"
4
+
5
+ # Suite of convenience functions to test if a UEN is for a specific entity
6
+ module IsUen
7
+ VALID_ENTITIES = %w[LP LL FC PF RF MQ MM NB CC CS MB FM GS DP CP NR CM CD MD HS VH CH MH CL XL
8
+ CX HC RP TU TC FB FN PA PB SS MC SM GA GB].freeze
9
+
10
+ YEARS = { "R" => "18", "S" => "19", "T" => "20" }.freeze
11
+ ENTITY_REGEX = /^(?<year>R|S|T)(?<decade>\d{2})(?<entity>[A-Z]{2})\d{4}[A-Z]$/.freeze
12
+
13
+ def uen?(id)
14
+ business?(id) || company?(id) || new_uen?(id)
15
+ end
16
+
17
+ def new_uen?(id)
18
+ match = ENTITY_REGEX.match(id)
19
+ return false unless match
20
+
21
+ VALID_ENTITIES.include?(match[:entity]) && valid_new_uen_year?(match)
22
+ end
23
+
24
+ def business?(id)
25
+ /^\d{8}[A-Z]$/.match?(id)
26
+ end
27
+
28
+ def company?(id)
29
+ match = /^(?<year>\d{4})\d{5}[A-Z]$/.match(id)
30
+ return false unless match
31
+
32
+ valid_year?(match[:year])
33
+ end
34
+
35
+ # FIXME: not sure how to effectively test these! will revisit
36
+ VALID_ENTITIES.each do |entity|
37
+ define_singleton_method "#{entity.downcase}?" do |id|
38
+ match = ENTITY_REGEX.match(id)
39
+ return false unless match
40
+
41
+ entity == match[:entity] && valid_new_uen_year?(match)
42
+ end
43
+ end
44
+
45
+ def self.valid_new_uen_year?(match)
46
+ year = YEARS[match[:year]] + match[:decade]
47
+ valid_year?(year)
48
+ end
49
+
50
+ def self.valid_year?(year_string)
51
+ year_string.to_i <= Time.now.year
52
+ end
53
+
54
+ private_class_method :valid_year?, :valid_new_uen_year?
55
+ module_function :uen?, :business?, :company?, :new_uen?
56
+ end
data/sig/is_uen.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module IsUen
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: is_uen
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - yaojie
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-01-24 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |
14
+ In Singapore, UEN is the standard identification number of an entity.
15
+ UEN shall be for registered entities as NRIC is for Singapore citizens.
16
+ The UEN uniquely identifies the entity.
17
+ From https://www.uen.gov.sg/ueninternet/faces/pages/admin/aboutUEN.jspx
18
+ email:
19
+ - limyaojie93@gmail.com
20
+ executables: []
21
+ extensions: []
22
+ extra_rdoc_files: []
23
+ files:
24
+ - ".rubocop.yml"
25
+ - Gemfile
26
+ - Gemfile.lock
27
+ - LICENSE.txt
28
+ - README.md
29
+ - Rakefile
30
+ - bin/console
31
+ - bin/setup
32
+ - lib/is_uen.rb
33
+ - lib/is_uen/version.rb
34
+ - sig/is_uen.rbs
35
+ homepage: https://www.github.com/causztic/is_uen
36
+ licenses:
37
+ - MIT
38
+ metadata:
39
+ allowed_push_host: https://rubygems.org
40
+ homepage_uri: https://www.github.com/causztic/is_uen
41
+ source_code_uri: https://www.github.com/causztic/is_uen
42
+ changelog_uri: https://www.github.com/causztic/is_uen/CHANGELOG.md
43
+ rubygems_mfa_required: 'true'
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 2.6.0
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ requirements: []
59
+ rubygems_version: 3.3.5
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: Checks whether a string is a valid UEN
63
+ test_files: []