validate_japanese 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +12 -6
- data/lib/locale/ja.yml +13 -0
- data/lib/validate_japanese/japanese_validator.rb +21 -4
- data/lib/validate_japanese/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9acfe3d1bdf887988fb7cc027645397c9140dee56ea2e1e69f5b1c9673869ece
|
4
|
+
data.tar.gz: 2e07b99e2d41d9bd93ceb7e115653fcc3ea53a5766c52ad7cd8a9489609184b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3575a2a96e8439acdb2e563c51e79707bbb7ee92b2b6e923eba8b9b9a44d3c739bc16b7ded4ba2f3be67da71bcb84b5a926ba08d0fbf82514019ba47d6ff9c54
|
7
|
+
data.tar.gz: d25db84555426d9c61ecd64352ee508c889b4ece7ae2f435f1543fceeebe418200d4119a4d6b41cef205ca5f2fe704c135f2cf57ef7958ca2cc8e44e09236816
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -26,23 +26,29 @@ class User < ApplicationRecord
|
|
26
26
|
# hiragana katakana hankaku_kana kanji suji zenkaku_suji choonpu
|
27
27
|
validates :name, japanese: true
|
28
28
|
|
29
|
-
#
|
29
|
+
# hiragana "ぁ-ん" + "ー-"
|
30
30
|
validates :name, japanese: {hiragana: true}
|
31
31
|
|
32
|
-
#
|
32
|
+
# katakana "ァ-ン" + "ー-"
|
33
33
|
validates :name, japanese: {katakana: true}
|
34
34
|
|
35
|
-
#
|
35
|
+
# hankaku_kana "ァ-ン゙゚" + "-"
|
36
36
|
validates :name, japanese: {hankaku_kana: true}
|
37
37
|
|
38
|
-
#
|
38
|
+
# kanji "一-龠々"
|
39
39
|
validates :name, japanese: {kanji: true}
|
40
40
|
|
41
|
-
#
|
41
|
+
# suji "0-9"
|
42
42
|
validates :name, japanese: {suji: true}
|
43
43
|
|
44
|
-
#
|
44
|
+
# zenkaku_suji "0-9"
|
45
45
|
validates :name, japanese: {zenkaku_suji: true}
|
46
|
+
|
47
|
+
# hiragana katakana "ぁ-ん" + "ァ-ン" + "ー-"
|
48
|
+
validates :name, japanese: {only: %i(hiragana katakana)}
|
49
|
+
|
50
|
+
# japanese + "、。"
|
51
|
+
validates :name, japanese: {concat: '、。'}
|
46
52
|
end
|
47
53
|
```
|
48
54
|
|
data/lib/locale/ja.yml
ADDED
@@ -5,6 +5,7 @@ module ActiveModel
|
|
5
5
|
SUFFIX = "\\z"
|
6
6
|
KUHAKU = "\\s"
|
7
7
|
CHOONPU = "ー-"
|
8
|
+
HANKAKU_CHOONPU = "\\-"
|
8
9
|
|
9
10
|
ALPHABET = "a-zA-Z"
|
10
11
|
ZENKAKU_ALPHABET = "a-zA-Z"
|
@@ -24,8 +25,8 @@ module ActiveModel
|
|
24
25
|
private
|
25
26
|
|
26
27
|
def build_regexp(options)
|
27
|
-
options = options.except(:message)
|
28
|
-
japanese = %i(hiragana katakana hankaku_kana kanji suji zenkaku_suji choonpu)
|
28
|
+
options = options.except(:message, :choonpu, :hankaku_choonpu, :prefix, :suffix, :kuhaku)
|
29
|
+
japanese = %i(hiragana katakana hankaku_kana kanji suji zenkaku_suji choonpu hankaku_choonpu)
|
29
30
|
keys = []
|
30
31
|
|
31
32
|
if options.empty?
|
@@ -34,17 +35,33 @@ module ActiveModel
|
|
34
35
|
keys.concat options[:only]
|
35
36
|
elsif options.has_key?(:concat)
|
36
37
|
keys.concat japanese
|
37
|
-
keys.concat options[:concat].map(&:to_sym).except(*japanese)
|
38
38
|
else
|
39
39
|
keys.concat options.select {|_, v| v}.keys
|
40
40
|
end
|
41
41
|
|
42
|
-
|
42
|
+
if (keys.include?(:hiragana) || keys.include?(:katakana)) && keys.exclude?(:choonpu)
|
43
|
+
keys << :choonpu
|
44
|
+
end
|
45
|
+
if keys.include?(:hankaku_kana) && keys.exclude?(:hankaku_choonpu)
|
46
|
+
keys << :hankaku_choonpu
|
47
|
+
end
|
48
|
+
|
49
|
+
base = keys.map(&method(:const)).join
|
50
|
+
|
51
|
+
if options.has_key?(:concat)
|
52
|
+
base += options[:concat].to_s
|
53
|
+
end
|
54
|
+
|
55
|
+
Regexp.new("#{PREFIX}[#{base}]+#{SUFFIX}")
|
43
56
|
end
|
44
57
|
|
45
58
|
def const(name)
|
46
59
|
self.class.const_get(name.upcase)
|
47
60
|
end
|
61
|
+
|
62
|
+
def available_kind
|
63
|
+
# TODO
|
64
|
+
end
|
48
65
|
end
|
49
66
|
end
|
50
67
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: validate_japanese
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ts-3156
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- gemfiles/ar_5.1.gemfile
|
107
107
|
- gemfiles/ar_5.2.gemfile
|
108
108
|
- lib/locale/en.yml
|
109
|
+
- lib/locale/ja.yml
|
109
110
|
- lib/validate_japanese.rb
|
110
111
|
- lib/validate_japanese/japanese_validator.rb
|
111
112
|
- lib/validate_japanese/version.rb
|