validate_japanese 0.4.1 → 0.4.2

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: a1125eae18b605eb80240b7e5113c0c150911b517245cf873e6a83444e8178bc
4
- data.tar.gz: fba0fc9c1d12ec4a7dc4e068d91aab2e3c8fb9ac38c6d4fd6a0330f24dd9ccff
3
+ metadata.gz: 612abb78a67e99c387a4005dda1c80a3235ba9d21a05f55e4d6344631153b802
4
+ data.tar.gz: df1f5f73ef2a5840d92753cd2882f683918f66e492705f1c37251ba4d44a3c24
5
5
  SHA512:
6
- metadata.gz: 704cddafdc01f91b21f96133c900d99eed6f33f97fcf109b1125a56fb41ba14a512c3adda31bce9c336a9be6c3c22321dde1e4f197e98cd7b81c977abb62885f
7
- data.tar.gz: 2fb39e0fd7fe91b56445ae0a130d431d54c9b7d63f9cf4a59dc3a88bb15325d1d584effcc12304220b3d8d29537e5f5d19530579bcc6bf577ddc65d8a46ed8a3
6
+ metadata.gz: dc3bc136ec6a20c7dea4110733a9d0610333ff669ff6d8e647e4187eea87387cfecd014e2f25c52d09142088df9fe5c07cf2b20782501d3391c291c3f9025a9c
7
+ data.tar.gz: 349189e1e7710d4b3c71ca39b59c472a7e26d6b193ccb6df6cdc68d31055431eea5a934df1c712c3f5e96809646f426b80ad4dbedc150cd18a2d6c073662ec2e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- validate_japanese (0.4.1)
4
+ validate_japanese (0.4.2)
5
5
  activerecord (>= 4.2, < 6.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -13,43 +13,93 @@ Add this line to your application’s Gemfile:
13
13
  gem 'validate_japanese'
14
14
  ```
15
15
 
16
- Add a validation rule to your model.
16
+ Add a validation rule to your model:
17
17
 
18
18
  ```ruby
19
- validates :name, japanese: true
19
+ class User < ApplicationRecord
20
+ validates :name, japanese: true
21
+ end
22
+ ```
23
+
24
+ I18n error message:
25
+
26
+ ```ruby
27
+ User.new(name: 'invalid name').tap(&:valid?)
28
+ # => Name に使える文字はひらがなカタカナ半角カナ漢字数字全角数字です。
20
29
  ```
21
30
 
22
31
  ## Usage
23
32
 
24
33
  ```ruby
25
- class User < ApplicationRecord
26
- # hiragana katakana hankaku_kana kanji suji zenkaku_suji "ー-" + "-"
27
- validates :name, japanese: true
34
+ # hiragana katakana hankaku_kana kanji suji zenkaku_suji "ー-" + "-"
35
+ validates :name, japanese: true
28
36
 
29
- # hiragana "ぁ-ん" + "ー-"
30
- validates :name, japanese: {hiragana: true}
37
+ user.errors.full_messages
38
+ # => Name に使える文字はひらがなカタカナ半角カナ漢字数字全角数字です。
39
+ ```
31
40
 
32
- # katakana "ァ-ン" + "ー-"
33
- validates :name, japanese: {katakana: true}
41
+ ```ruby
42
+ # hiragana "ぁ-ん" + "ー-"
43
+ validates :name, japanese: {hiragana: true}
34
44
 
35
- # hankaku_kana "ァ-ン゙゚" + "-"
36
- validates :name, japanese: {hankaku_kana: true}
45
+ user.errors.full_messages
46
+ # => Name に使える文字はひらがなです。
47
+ ```
37
48
 
38
- # kanji "一-龠々"
39
- validates :name, japanese: {kanji: true}
49
+ ```ruby
50
+ # katakana "ァ-ン" + "ー-"
51
+ validates :name, japanese: {katakana: true}
40
52
 
41
- # suji "0-9"
42
- validates :name, japanese: {suji: true}
53
+ user.errors.full_messages
54
+ # => Name に使える文字はカタカナです。
55
+ ```
43
56
 
44
- # zenkaku_suji "0-9"
45
- validates :name, japanese: {zenkaku_suji: true}
57
+ ```ruby
58
+ # hankaku_kana "ァ-ン゙゚" + "-"
59
+ validates :name, japanese: {hankaku_kana: true}
46
60
 
47
- # hiragana katakana "ぁ-ん" + "ァ-ン" + "ー-"
48
- validates :name, japanese: {only: %i(hiragana katakana)}
61
+ user.errors.full_messages
62
+ # => Name に使える文字は半角カナです。
63
+ ```
49
64
 
50
- # japanese "、。"
51
- validates :name, japanese: {concat: '、。'}
52
- end
65
+ ```ruby
66
+ # kanji "一-龠々"
67
+ validates :name, japanese: {kanji: true}
68
+
69
+ user.errors.full_messages
70
+ # => Name に使える文字は漢字です。
71
+ ```
72
+
73
+ ```ruby
74
+ # suji "0-9"
75
+ validates :name, japanese: {suji: true}
76
+
77
+ user.errors.full_messages
78
+ # => Name に使える文字は数字です。
79
+ ```
80
+
81
+ ```ruby
82
+ # zenkaku_suji "0-9"
83
+ validates :name, japanese: {zenkaku_suji: true}
84
+
85
+ user.errors.full_messages
86
+ # => Name に使える文字は全角数字です。
87
+ ```
88
+
89
+ ```ruby
90
+ # hiragana katakana "ぁ-ん" + "ァ-ン" + "ー-"
91
+ validates :name, japanese: {only: %i(hiragana katakana)}
92
+
93
+ user.errors.full_messages
94
+ # => Name に使える文字はひらがなカタカナです。
95
+ ```
96
+
97
+ ```ruby
98
+ # japanese "、。"
99
+ validates :name, japanese: {concat: '、。'}
100
+
101
+ user.errors.full_messages
102
+ # => Name に使える文字はひらがなカタカナ半角カナ漢字数字全角数字、。です。
53
103
  ```
54
104
 
55
105
  ## Implementation
@@ -23,7 +23,7 @@ module ActiveModel
23
23
  if options[:message]
24
24
  record.errors.add(attribute, options[:message])
25
25
  else
26
- record.errors.add(attribute, :invalid_japanese, kind: available_kind(keys))
26
+ record.errors.add(attribute, :invalid_japanese, kind: available_kind(keys, concat: options[:concat]))
27
27
  end
28
28
  end
29
29
  end
@@ -65,8 +65,10 @@ module ActiveModel
65
65
  self.class.const_get(name.upcase)
66
66
  end
67
67
 
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)
68
+ def available_kind(keys, concat: nil, sep: '')
69
+ kind = keys.reject {|k| %i(choonpu hankaku_choonpu).include?(k)}.map {|k| I18n.t("validate_japanese.#{k}")}.join(sep)
70
+ kind += concat if concat
71
+ kind
70
72
  end
71
73
  end
72
74
  end
@@ -1,3 +1,3 @@
1
1
  module ValidateJapanese
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
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.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ts-3156