Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Allow space option #6

Merged
merged 6 commits into from
Mar 22, 2019
Merged

Add Allow space option #6

merged 6 commits into from
Mar 22, 2019

Conversation

nmbakfm
Copy link
Contributor

@nmbakfm nmbakfm commented Dec 6, 2017

add allow_space option to katakana and hiragana

like this:

validates hiragana: { allow_space: true }
validates katakana: { allow_space: true }

@nmbakfm nmbakfm self-assigned this Dec 6, 2017
[
' ',
' カタ カナー ',
'カタ カナー',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

context 'valid katakana(allow_space)' do
[
' ',
' カタ カナー ',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.


context 'valid katakana(allow_space)' do
[
' ',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

].each do |katakana|
it "#{katakana} should be valid" do
expect(KatakanaModel.new(katakana: katakana)).not_to be_valid
end
end
end

context 'valid katakana(allow_space)' do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

].each do |katakana|
it "#{katakana} should be valid" do
expect(KatakanaModel.new(katakana: katakana)).not_to be_valid
end
end
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace detected.

].each do |hiragana|
it "#{hiragana} should be valid" do
expect(HiraganaModel.new(hiragana: hiragana)).not_to be_valid
end
end
end

context 'valid hiragana' do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

].each do |hiragana|
it "#{hiragana} should be valid" do
expect(HiraganaModel.new(hiragana: hiragana)).not_to be_valid
end
end
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace detected.

@@ -24,10 +28,23 @@ class HiraganaModel < TestModel
'カタカナ',
'漢字',
'ひらがなとカタカナ',
'ひら がなー',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

@@ -1,3 +1,3 @@
module Roshi
VERSION = '0.8.0'
VERSION = '0.8.1'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Freeze mutable objects assigned to constants.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

@@ -2,7 +2,8 @@ module ActiveModel
module Validations
class KatakanaValidator < EachValidator
def validate_each(record, attribute, value)
unless value =~ /\A[\p{katakana}ー-]*\z/i
space = options[:allow_space] ? '[:blank:]' : ""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

[
' ',
' カタ カナー ',
'カタ カナー'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

describe 'KatakanaValidator' do
context 'valid katakana' do
[
'',
'カタカナ',
'カタカナー',
'カタカナー'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

[
' ',
' ひら がな ',
'ひら がなー'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

@@ -24,10 +28,23 @@ class HiraganaModel < TestModel
'カタカナ',
'漢字',
'ひらがなとカタカナ',
'ひら がなー'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

describe 'HiraganaValidator' do
context 'valid hiragana' do
[
'',
'ひらがな',
'ひらがなー',
'ひらがなー'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

@nmbakfm
Copy link
Contributor Author

nmbakfm commented Dec 6, 2017

@kawahiro311 @Kta-M review this.

@@ -2,7 +2,8 @@ module ActiveModel
module Validations
class KatakanaValidator < EachValidator
def validate_each(record, attribute, value)
unless value =~ /\A[\p{katakana}ー-]*\z/i
space = options[:allow_space] ? '[:blank:]' : ''

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

[
' ',
' カタ カナー ',
'カタ カナー'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

context 'valid katakana(allow_space)' do
[
' ',
' カタ カナー ',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.


context 'valid katakana(allow_space)' do
[
' ',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

].each do |katakana|
it "#{katakana} should be valid" do
expect(KatakanaModel.new(katakana: katakana)).not_to be_valid
end
end
end

context 'valid katakana(allow_space)' do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

].each do |hiragana|
it "#{hiragana} should be valid" do
expect(HiraganaModel.new(hiragana: hiragana)).not_to be_valid
end
end
end

context 'valid hiragana' do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

].each do |hiragana|
it "#{hiragana} should be valid" do
expect(HiraganaModel.new(hiragana: hiragana)).not_to be_valid
end
end
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/TrailingWhitespace: Trailing whitespace detected.

@@ -24,10 +28,23 @@ class HiraganaModel < TestModel
'カタカナ',
'漢字',
'ひらがなとカタカナ',
'ひら がなー'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

describe 'HiraganaValidator' do
context 'valid hiragana' do
[
'',
'ひらがな',
'ひらがなー',
'ひらがなー'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

@@ -2,7 +2,8 @@ module ActiveModel
module Validations
class HiraganaValidator < EachValidator
def validate_each(record, attribute, value)
unless value =~ /\A[\p{hiragana}ー-]*\z/i
space = options[:allow_space] ? '[:blank:]' : ''

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Copy link
Member

@Kta-M Kta-M left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok farm!

@nmbakfm nmbakfm merged commit 22e7574 into master Mar 22, 2019
@nmbakfm nmbakfm deleted the allow_space_option branch March 22, 2019 01:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants