roshi 0.8.0 → 0.9.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
- SHA1:
3
- metadata.gz: 96f2b09d4f9a2cfc7266be05fee56a50bbad6609
4
- data.tar.gz: 673294fba72c81de66be3d7a6f13b7ed4f8e9a21
2
+ SHA256:
3
+ metadata.gz: '0299322983ffc79bebf28dc2f3fe565358cccc519c951431b4334956ddc0bd15'
4
+ data.tar.gz: 8a411586358501cbaba8bdac48a2f138995fecca26c08946c4aa6fd56d69bc9a
5
5
  SHA512:
6
- metadata.gz: dd07de35b85f1b1211b6831d4f70e69ad2f06a5ad3790252ba167871bc4a12468127558b73007a6df0820b3d005ea5465b66b4f348fea5df181727f70995c07b
7
- data.tar.gz: b5ad9b612f018af303a5d806694078574226c395abad44fa7ff6c0d6fdba3ad4041daa74eb7a9f3c3bfc7df597f4d5f98599d14136be6bc19ece295ab0e7db95
6
+ metadata.gz: 29f04b76606b7bcf6db5f0055f2841c3db9f6719cbed77d5ca1b2a344077953144af44c1e2dc7b6bd6806bf0829a0cf422befefec95c60f764f177b07d7a01d1
7
+ data.tar.gz: b6152c193cc72fdcfa8e69273f912da792274c685832b45a4d6311a02bd49faee786e2f9be5cb11cfbd8e4715f14db71cacb17fd511e77e08c4ed6621988cd2d
data/README.md CHANGED
@@ -29,10 +29,11 @@ class TestModel
29
29
  validates :zip_code, zip_code: true # zip_code: { hiphenation: true }
30
30
  validates :phone_number, phone_number: true # phone_number: { hiphenation: true }
31
31
  validates :date, date: true
32
- validates :hiragana, hiragana: true
32
+ validates :hiragana, hiragana: true # hiragana: { allow_space: true }
33
+ validates :katakana, katakana: true # katakana: { allow_space: true }
33
34
  validates :version_number, version_number: true
34
- validates :accept_word, available_word: {accept_words: %w(accept available)}
35
- validates :reject_word, available_word: {reject_words: %w(reject unavailable)}
35
+ validates :accept_word, available_word: { accept_words: %w(accept available) }
36
+ validates :reject_word, available_word: { reject_words: %w(reject unavailable) }
36
37
  validates :large_value, numerical_comparison: { greater_than: :small_value }
37
38
  validates :large_value, numerical_comparison: { greater_than_or_equal_to: :small_value }
38
39
  validates :large_value, numerical_comparison: { equal_to: :small_value }
data/lib/roshi.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'active_model'
2
2
  require 'roshi/version'
3
3
  %w(
4
- email zip_code phone_number date hiragana
4
+ email zip_code phone_number date hiragana katakana
5
5
  version_number available_word numerical_comparison
6
6
  ).each do |validator_name|
7
7
  require "roshi/active_model/validations/#{validator_name}_validator"
@@ -3,7 +3,7 @@ module ActiveModel
3
3
  class EmailValidator < EachValidator
4
4
  def validate_each(record, attribute, value)
5
5
  # http://emailregex.com
6
- unless value =~ /\A([\w+!#$%&'*+\/=?^`{|}~\-].?)+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i
6
+ unless value =~ URI::MailTo::EMAIL_REGEXP
7
7
  record.errors.add(attribute, options[:message] || I18n.t('errors.messages.invalid'))
8
8
  end
9
9
  end
@@ -2,7 +2,8 @@ module ActiveModel
2
2
  module Validations
3
3
  class HiraganaValidator < EachValidator
4
4
  def validate_each(record, attribute, value)
5
- unless value =~ /\A[\p{hiragana}ー-]*\z/i
5
+ space = options[:allow_space] ? '[:blank:]' : ''
6
+ unless value =~ /\A[\p{hiragana}#{space}ー-]*\z/i
6
7
  record.errors.add(attribute, options[:message] || I18n.t('errors.messages.invalid'))
7
8
  end
8
9
  end
@@ -0,0 +1,12 @@
1
+ module ActiveModel
2
+ module Validations
3
+ class KatakanaValidator < EachValidator
4
+ def validate_each(record, attribute, value)
5
+ space = options[:allow_space] ? '[:blank:]' : ''
6
+ unless value =~ /\A[\p{katakana}ー-#{space}]*\z/i
7
+ record.errors.add(attribute, options[:message] || I18n.t('errors.messages.invalid'))
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -2,9 +2,9 @@ module ActiveModel
2
2
  module Validations
3
3
  class PhoneNumberValidator < EachValidator
4
4
  REGEXES = {
5
- default: /\A\d{2,4}\-?\d{2,4}\-?\d{4}\z/i,
6
- with_hiphenation: /\A\d{2,4}\-\d{2,4}\-\d{4}\z/i,
7
- without_hiphenation: /\A\d{6,12}\z/i
5
+ default: /\A0\d{1,4}\-?\d{1,4}\-?\d{1,4}\z/i,
6
+ with_hiphenation: /\A0\d{1,4}\-\d{1,4}\-\d{1,4}\z/i,
7
+ without_hiphenation: /\A0\d{9,10}\z/i
8
8
  }
9
9
 
10
10
  def validate_each(record, attribute, value)
@@ -16,8 +16,8 @@ module ActiveModel
16
16
  when options[:hiphenation] == false
17
17
  REGEXES[:without_hiphenation]
18
18
  end
19
-
20
- unless value =~ regexp
19
+ valid_length = [10, 11].include?((value.gsub('-', '').length))
20
+ unless value =~ regexp && valid_length
21
21
  record.errors.add(attribute, options[:message] || I18n.t('errors.messages.invalid'))
22
22
  end
23
23
  end
data/lib/roshi/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Roshi
2
- VERSION = '0.8.0'
2
+ VERSION = '0.9.0'
3
3
  end
data/roshi.gemspec CHANGED
@@ -6,8 +6,8 @@ require 'roshi/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = 'roshi'
8
8
  spec.version = Roshi::VERSION
9
- spec.authors = ['kawahiro311', 'Kta-M']
10
- spec.email = ['hiro.kawasaki0311@gmail.com', 'mohri1219@gmail.com']
9
+ spec.authors = ['kawahiro311', 'Kta-M', 'nmbakfm']
10
+ spec.email = ['hiro.kawasaki0311@gmail.com', 'mohri1219@gmail.com', 'nmbakfm@gmail.com']
11
11
 
12
12
  spec.summary = %q{ActiveModel/ActiveRecord Validation Collection}
13
13
  spec.description = %q{ActiveModel/ActiveRecord Validation Collection For Mainly Japanese}
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
 
19
19
  spec.add_dependency 'activemodel'
20
20
  spec.add_development_dependency 'bundler', "~> 1.9"
21
- spec.add_development_dependency 'rake', "~> 10.0"
21
+ spec.add_development_dependency 'rake', "~> 12.3.3"
22
22
  spec.add_development_dependency 'rspec'
23
23
  spec.add_development_dependency 'pry'
24
24
  end
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roshi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kawahiro311
8
8
  - Kta-M
9
+ - nmbakfm
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2016-05-26 00:00:00.000000000 Z
13
+ date: 2021-03-04 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: activemodel
@@ -45,14 +46,14 @@ dependencies:
45
46
  requirements:
46
47
  - - "~>"
47
48
  - !ruby/object:Gem::Version
48
- version: '10.0'
49
+ version: 12.3.3
49
50
  type: :development
50
51
  prerelease: false
51
52
  version_requirements: !ruby/object:Gem::Requirement
52
53
  requirements:
53
54
  - - "~>"
54
55
  - !ruby/object:Gem::Version
55
- version: '10.0'
56
+ version: 12.3.3
56
57
  - !ruby/object:Gem::Dependency
57
58
  name: rspec
58
59
  requirement: !ruby/object:Gem::Requirement
@@ -85,6 +86,7 @@ description: ActiveModel/ActiveRecord Validation Collection For Mainly Japanese
85
86
  email:
86
87
  - hiro.kawasaki0311@gmail.com
87
88
  - mohri1219@gmail.com
89
+ - nmbakfm@gmail.com
88
90
  executables: []
89
91
  extensions: []
90
92
  extra_rdoc_files: []
@@ -101,6 +103,7 @@ files:
101
103
  - lib/roshi/active_model/validations/date_validator.rb
102
104
  - lib/roshi/active_model/validations/email_validator.rb
103
105
  - lib/roshi/active_model/validations/hiragana_validator.rb
106
+ - lib/roshi/active_model/validations/katakana_validator.rb
104
107
  - lib/roshi/active_model/validations/numerical_comparison_validator.rb
105
108
  - lib/roshi/active_model/validations/phone_number_validator.rb
106
109
  - lib/roshi/active_model/validations/version_number_validator.rb
@@ -125,8 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
128
  - !ruby/object:Gem::Version
126
129
  version: '0'
127
130
  requirements: []
128
- rubyforge_project:
129
- rubygems_version: 2.5.1
131
+ rubygems_version: 3.0.3
130
132
  signing_key:
131
133
  specification_version: 4
132
134
  summary: ActiveModel/ActiveRecord Validation Collection