domain_validator-jp 0.1.2

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
+ SHA256:
3
+ metadata.gz: 35485d41722280b27e4a225e32c23fb6445cac5b45a6388fcba4cd0bc3fb695a
4
+ data.tar.gz: 304e5154f0f17e159d2bdeb785d13cd975ac64161a9ff96989a93ec0ac466efc
5
+ SHA512:
6
+ metadata.gz: 8d253b768a9c212cad85cf142c65553bee56c725941a5c4899aa094bb8e19c51112e77282134836dded9ec884aaceeb8418cacbe607cab8139080b792dda46c9
7
+ data.tar.gz: 2a5feadd73248f14cb83e64fc6c887cda914f3e9f02f60f8535cf1b449455173054de06161b6d8913c3e66255ca565821cd20bb63a93af6977d380c9661684d1
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ /.bundle/
10
+ /vendor/
11
+ /Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3
4
+ - 2.4
5
+ - 2.5
6
+ script:
7
+ - bundle exec rspec
8
+ notifications:
9
+ slack:
10
+ secure: X5ENcwG/TTEjEi8hfhmX8Y0NMJPh4oUEEOOzR3XuPZ6NgnHIVxxLhSa+kqHrx7QwYx7YRUayLhhXst1n7fBOHdTpidvGZwLJnr6REnFNgwcevhFly6+o5dA5BpZPji3YQD3esTLfSDec29iG6Y19M2mrGSZFjsZR7PAcVpCs5Qj6Te45jpnH7gm57xsQUorpFJMi+Zm+O68VxwiMoiMcr/BvMidsMJxeGcdqZUCnXN4QTQvSKDTy0Uugpoavw0sceokZDjEirLKGluXAJUb5ovtRE0tgkp2Ruj4mk6gRljHwHxaDZ9dlkbbgtW1wSRrbP3VzHKNcIVrUN505bRV3yOddEmF0iP49cykTPIxLCSzqV3TPA+wgSfP0f11olFczTEo8KCuxAjV+wfG5XZjiTRMXMglCLuw1MpuSfcehRwahCYQzejGmXR7tzKLmtUJZE1LmziHqVCW3KVs3AaiwILNXm3InzO1vjCQX/AzBzP/SPiQnlwtUZtXSQglfmQadjJhFYsR+NKXbVJJlQlgYUEtRZ9lQHvU+sYLz+nLHv0HpGDz+/Z2UIkqB1o/ySFEatHShHftzEUC0PJ7lIqEnYZ3twWhbX1P7r+4F6eZnk8WXFvV+fCBrNM8tHBR1kBACnW6OlS9ROTFb6slknQE1oc/SWiHeZMC+tgAnR4QAl1I=
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2018 kimromi
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/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # :jp: DomainValidator::Jp
2
+
3
+ <a href="https://rubygems.org/gems/domain-validator-jp" title="npm"><img src="https://img.shields.io/gem/v/domain-validator-jp.svg"></a>
4
+ <a href="https://travis-ci.org/kimromi/domain-validator-jp" title="travis"><img src="https://img.shields.io/travis/kimromi/domain-validator-jp.svg"></a>
5
+ <a href="https://github.com/kimromi/domain-validator-jp/blob/master/LICENSE" title="MIT License"><img src="https://img.shields.io/badge/license-MIT-blue.svg"></a>
6
+
7
+ domain name validator includes JP domain
8
+
9
+ ## Usage
10
+
11
+ ```rb
12
+ DomainValidator::Jp.new('example.jp').valid? # => true
13
+ DomainValidator::Jp.new('日本語.jp').valid? # => true
14
+
15
+ DomainValidator::Jp.new('①②③.jp').valid? # => false
16
+ DomainValidator::Jp.new('example.wrongtld').valid? # => false
17
+ ```
18
+
19
+ ## Installation
20
+
21
+ Add this line to your application's Gemfile:
22
+
23
+ ```ruby
24
+ gem 'domain_validator-jp'
25
+ ```
26
+
27
+ And then execute:
28
+
29
+ $ bundle
30
+
31
+ Or install it yourself as:
32
+
33
+ $ gem install domain_validator-jp
34
+
35
+ ## Development
36
+
37
+ 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.
38
+
39
+ 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).
40
+
41
+ ## Contributing
42
+
43
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kimromi/domain-validator-jp.
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+ RSpec::Core::RakeTask.new(:spec)
4
+
5
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "domain_validator-jp"
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(__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,28 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "domain_validator/jp/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "domain_validator-jp"
8
+ spec.version = DomainValidator::Jp::VERSION
9
+ spec.authors = ["kimromi"]
10
+ spec.email = ["kimromi4@gmail.com"]
11
+
12
+ spec.summary = %q{domain name validator includes JP domain}
13
+ spec.description = %q{domain name validator includes JP domain}
14
+ spec.homepage = "https://github.com/kimromi/domain_validator-jp"
15
+
16
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
17
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ end
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency "public_suffix"
24
+ spec.add_development_dependency "bundler", "~> 1.16"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec"
27
+ spec.add_development_dependency "pry-byebug"
28
+ end
@@ -0,0 +1,7 @@
1
+ require "domain_validator/jp/version"
2
+ require "domain_validator/jp"
3
+
4
+ module DomainValidator
5
+ class Jp
6
+ end
7
+ end
@@ -0,0 +1,97 @@
1
+ require "public_suffix"
2
+
3
+ module DomainValidator
4
+ class Jp
5
+ attr_reader :domain
6
+
7
+ def initialize(domain)
8
+ @domain = domain
9
+ end
10
+
11
+ def valid?
12
+ return false if include_subdomain?
13
+ return false unless valid_public_suffix?
14
+ return false unless valid_sld_not_dotted?
15
+ return false unless valid_sld_not_start_with_hyphen?
16
+ return false unless valid_sld_not_end_with_hyphen?
17
+
18
+ if sld_multibyte?
19
+ return false unless valid_length_sld_multibyte?
20
+ return false unless valid_jisx0208?
21
+ else
22
+ return false unless valid_sld_chars?
23
+ return false unless valid_length_domain?
24
+ return false unless valid_length_sld?
25
+ end
26
+
27
+ true
28
+ end
29
+
30
+ def parsed
31
+ @parsed ||= PublicSuffix.parse(domain)
32
+ end
33
+
34
+ def sld
35
+ parsed.sld
36
+ end
37
+
38
+ def tld
39
+ parsed.tld
40
+ end
41
+
42
+ # common
43
+
44
+ def include_subdomain?
45
+ !parsed.subdomain.nil?
46
+ end
47
+
48
+ def valid_public_suffix?
49
+ PublicSuffix.valid?(domain, default_rule: nil, ignore_private: true)
50
+ end
51
+
52
+ def valid_sld_not_dotted?
53
+ sld !~ /\./
54
+ end
55
+
56
+ def valid_sld_not_start_with_hyphen?
57
+ sld !~ /^\-/
58
+ end
59
+
60
+ def valid_sld_not_end_with_hyphen?
61
+ sld !~ /\-$/
62
+ end
63
+
64
+ # only multibyte
65
+
66
+ def sld_multibyte?
67
+ sld !~ /^[0-9A-Za-z\-]+$/
68
+ end
69
+
70
+ def valid_length_sld_multibyte?
71
+ 1 <= sld.length && sld.length <= 15
72
+ end
73
+
74
+ # only multibyte
75
+
76
+ def valid_sld_chars?
77
+ sld =~ /^[0-9A-Za-z\-]+$/
78
+ end
79
+
80
+ def valid_length_domain?
81
+ domain.length <= 253
82
+ end
83
+
84
+ def valid_length_sld?
85
+ sld.length <= 63
86
+ end
87
+
88
+ def valid_jisx0208?
89
+ valid = /^#{utf8_to_sjis("[\-0-9A-Za-zぁ-んァ-ヶ亜-腕弌-熙]")}+$/
90
+ valid.match(utf8_to_sjis(sld)) if utf8_to_sjis(sld)
91
+ end
92
+
93
+ def utf8_to_sjis(str)
94
+ str.encode('Windows-31J') rescue nil
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,5 @@
1
+ module DomainValidator
2
+ class Jp
3
+ VERSION = "0.1.2"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: domain_validator-jp
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - kimromi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-06-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: public_suffix
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
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: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.16'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
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: pry-byebug
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
+ description: domain name validator includes JP domain
84
+ email:
85
+ - kimromi4@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/setup
99
+ - domain_validator-jp.gemspec
100
+ - lib/domain_validator-jp.rb
101
+ - lib/domain_validator/jp.rb
102
+ - lib/domain_validator/jp/version.rb
103
+ homepage: https://github.com/kimromi/domain_validator-jp
104
+ licenses: []
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.7.3
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: domain name validator includes JP domain
126
+ test_files: []