validate_japanese 0.4.0 → 0.4.1
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 +2 -2
- data/lib/locale/ja.yml +1 -1
- data/lib/validate_japanese/japanese_validator.rb +11 -5
- data/lib/validate_japanese/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1125eae18b605eb80240b7e5113c0c150911b517245cf873e6a83444e8178bc
|
4
|
+
data.tar.gz: fba0fc9c1d12ec4a7dc4e068d91aab2e3c8fb9ac38c6d4fd6a0330f24dd9ccff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 704cddafdc01f91b21f96133c900d99eed6f33f97fcf109b1125a56fb41ba14a512c3adda31bce9c336a9be6c3c22321dde1e4f197e98cd7b81c977abb62885f
|
7
|
+
data.tar.gz: 2fb39e0fd7fe91b56445ae0a130d431d54c9b7d63f9cf4a59dc3a88bb15325d1d584effcc12304220b3d8d29537e5f5d19530579bcc6bf577ddc65d8a46ed8a3
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -23,7 +23,7 @@ validates :name, japanese: true
|
|
23
23
|
|
24
24
|
```ruby
|
25
25
|
class User < ApplicationRecord
|
26
|
-
# hiragana katakana hankaku_kana kanji suji zenkaku_suji
|
26
|
+
# hiragana katakana hankaku_kana kanji suji zenkaku_suji "ー-" + "-"
|
27
27
|
validates :name, japanese: true
|
28
28
|
|
29
29
|
# hiragana "ぁ-ん" + "ー-"
|
@@ -47,7 +47,7 @@ class User < ApplicationRecord
|
|
47
47
|
# hiragana katakana "ぁ-ん" + "ァ-ン" + "ー-"
|
48
48
|
validates :name, japanese: {only: %i(hiragana katakana)}
|
49
49
|
|
50
|
-
# japanese
|
50
|
+
# japanese "、。"
|
51
51
|
validates :name, japanese: {concat: '、。'}
|
52
52
|
end
|
53
53
|
```
|
data/lib/locale/ja.yml
CHANGED
@@ -17,8 +17,14 @@ module ActiveModel
|
|
17
17
|
ZENKAKU_SUJI = "0-9"
|
18
18
|
|
19
19
|
def validate_each(record, attribute, value)
|
20
|
-
|
21
|
-
|
20
|
+
keys, regexp = build_regexp(options)
|
21
|
+
|
22
|
+
unless value.to_s.match? regexp
|
23
|
+
if options[:message]
|
24
|
+
record.errors.add(attribute, options[:message])
|
25
|
+
else
|
26
|
+
record.errors.add(attribute, :invalid_japanese, kind: available_kind(keys))
|
27
|
+
end
|
22
28
|
end
|
23
29
|
end
|
24
30
|
|
@@ -52,15 +58,15 @@ module ActiveModel
|
|
52
58
|
base += options[:concat].to_s
|
53
59
|
end
|
54
60
|
|
55
|
-
Regexp.new("#{PREFIX}[#{base}]+#{SUFFIX}")
|
61
|
+
[keys, Regexp.new("#{PREFIX}[#{base}]+#{SUFFIX}")]
|
56
62
|
end
|
57
63
|
|
58
64
|
def const(name)
|
59
65
|
self.class.const_get(name.upcase)
|
60
66
|
end
|
61
67
|
|
62
|
-
def available_kind
|
63
|
-
|
68
|
+
def available_kind(keys, sep = '')
|
69
|
+
keys.reject {|k| %i(choonpu hankaku_choonpu).include?(k)}.map {|k| I18n.t("validate_japanese.#{k}")}.join(sep)
|
64
70
|
end
|
65
71
|
end
|
66
72
|
end
|