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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9acfe3d1bdf887988fb7cc027645397c9140dee56ea2e1e69f5b1c9673869ece
4
- data.tar.gz: 2e07b99e2d41d9bd93ceb7e115653fcc3ea53a5766c52ad7cd8a9489609184b2
3
+ metadata.gz: a1125eae18b605eb80240b7e5113c0c150911b517245cf873e6a83444e8178bc
4
+ data.tar.gz: fba0fc9c1d12ec4a7dc4e068d91aab2e3c8fb9ac38c6d4fd6a0330f24dd9ccff
5
5
  SHA512:
6
- metadata.gz: 3575a2a96e8439acdb2e563c51e79707bbb7ee92b2b6e923eba8b9b9a44d3c739bc16b7ded4ba2f3be67da71bcb84b5a926ba08d0fbf82514019ba47d6ff9c54
7
- data.tar.gz: d25db84555426d9c61ecd64352ee508c889b4ece7ae2f435f1543fceeebe418200d4119a4d6b41cef205ca5f2fe704c135f2cf57ef7958ca2cc8e44e09236816
6
+ metadata.gz: 704cddafdc01f91b21f96133c900d99eed6f33f97fcf109b1125a56fb41ba14a512c3adda31bce9c336a9be6c3c22321dde1e4f197e98cd7b81c977abb62885f
7
+ data.tar.gz: 2fb39e0fd7fe91b56445ae0a130d431d54c9b7d63f9cf4a59dc3a88bb15325d1d584effcc12304220b3d8d29537e5f5d19530579bcc6bf577ddc65d8a46ed8a3
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- validate_japanese (0.4.0)
4
+ validate_japanese (0.4.1)
5
5
  activerecord (>= 4.2, < 6.0)
6
6
 
7
7
  GEM
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 choonpu
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
@@ -1,5 +1,5 @@
1
1
  en:
2
- dic:
2
+ validate_japanese:
3
3
  hiragana: ひらがな
4
4
  katakana: カタカナ
5
5
  hankaku_kana: 半角カナ
@@ -17,8 +17,14 @@ module ActiveModel
17
17
  ZENKAKU_SUJI = "0-9"
18
18
 
19
19
  def validate_each(record, attribute, value)
20
- unless value.to_s.match? build_regexp(options)
21
- record.errors.add(attribute, options[:message] || :invalid)
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
- # TODO
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
@@ -1,3 +1,3 @@
1
1
  module ValidateJapanese
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  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.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ts-3156