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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f23f115e40c7bd4b713fe9d9c2ef28517cc6ad764c8599492000202808e379f6
4
- data.tar.gz: ba56c45e85a420e57fd5e838a0e6a799325149029a1d32fff18ebcad42f5a4fe
3
+ metadata.gz: 9acfe3d1bdf887988fb7cc027645397c9140dee56ea2e1e69f5b1c9673869ece
4
+ data.tar.gz: 2e07b99e2d41d9bd93ceb7e115653fcc3ea53a5766c52ad7cd8a9489609184b2
5
5
  SHA512:
6
- metadata.gz: bc166b08fe163b7a25432e9f0cdd4824b438b159b79a0711bd566be83900c3410c435bd0824f61b791944ad9cc4ef12728f6fef2c3d11432eabe265ac84bd9bd
7
- data.tar.gz: 9bc69cdcfa60c1a15429fd82ca9bbb70b355a1d9afb28aabcebb8aa32af8f94deab09792e913aa8c2fb4d4b77145c755fc5cea80d2537717b8240ec0c04cd3e4
6
+ metadata.gz: 3575a2a96e8439acdb2e563c51e79707bbb7ee92b2b6e923eba8b9b9a44d3c739bc16b7ded4ba2f3be67da71bcb84b5a926ba08d0fbf82514019ba47d6ff9c54
7
+ data.tar.gz: d25db84555426d9c61ecd64352ee508c889b4ece7ae2f435f1543fceeebe418200d4119a4d6b41cef205ca5f2fe704c135f2cf57ef7958ca2cc8e44e09236816
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- validate_japanese (0.3.0)
4
+ validate_japanese (0.4.0)
5
5
  activerecord (>= 4.2, < 6.0)
6
6
 
7
7
  GEM
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
- # only hiragana "ぁ-ん"
29
+ # hiragana "ぁ-ん" + "ー-"
30
30
  validates :name, japanese: {hiragana: true}
31
31
 
32
- # only katakana "ァ-ン"
32
+ # katakana "ァ-ン" + "ー-"
33
33
  validates :name, japanese: {katakana: true}
34
34
 
35
- # only hankaku_kana "ァ-ン゙゚"
35
+ # hankaku_kana "ァ-ン゙゚" + "-"
36
36
  validates :name, japanese: {hankaku_kana: true}
37
37
 
38
- # only kanji "一-龠々"
38
+ # kanji "一-龠々"
39
39
  validates :name, japanese: {kanji: true}
40
40
 
41
- # only suji "0-9"
41
+ # suji "0-9"
42
42
  validates :name, japanese: {suji: true}
43
43
 
44
- # only zenkaku_suji "0-9"
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
@@ -0,0 +1,13 @@
1
+ en:
2
+ dic:
3
+ hiragana: ひらがな
4
+ katakana: カタカナ
5
+ hankaku_kana: 半角カナ
6
+ kanji: 漢字
7
+ suji: 数字
8
+ zenkaku_suji: 全角数字
9
+ alphabet: 英字
10
+ zenkaku_alphabet: 全角英字
11
+ errors:
12
+ messages:
13
+ invalid_japanese: に使える文字は%{kind}です。
@@ -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
- Regexp.new("#{PREFIX}[#{keys.map(&method(:const)).join}]+#{SUFFIX}")
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
@@ -1,3 +1,3 @@
1
1
  module ValidateJapanese
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
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.3.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