formkeeper-japanese 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ vendor/bundle
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in formkeeper-japanese.gemspec
4
+ gemspec
5
+
6
+ gem "hpricot"
7
+ gem "rack"
8
+ gem "moji"
9
+ gem "formkeeper", "~> 0.0.4"
10
+
11
+ group :development, :test do
12
+ gem "rspec"
13
+ gem "rake"
14
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 lyokato
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # FormKeeper::Japanese
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'formkeeper-japanese'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install formkeeper-japanese
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ desc "run spec"
5
+ RSpec::Core::RakeTask.new(:spec) do |t|
6
+ t.rspec_opts = ["-c", "-fs"]
7
+ end
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'formkeeper/japanese/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "formkeeper-japanese"
8
+ gem.version = FormKeeper::Japanese::VERSION
9
+ gem.authors = ["lyokato"]
10
+ gem.email = ["lyo.kato@gmail.com"]
11
+ gem.description = %q{formkeeper's plugin for japanese specific filters and validators}
12
+ gem.summary = %q{This module provides you japanese specific filters and validators}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
20
+
@@ -0,0 +1,71 @@
1
+ require "formkeeper/japanese/version"
2
+ require "moji"
3
+
4
+ module FormKeeper
5
+ module Japanese
6
+ module Filter
7
+ class ZenkakuToHankaku < ::FormKeeper::Filter::Base
8
+ def process(value)
9
+ Moji.zen_to_han(value)
10
+ end
11
+ end
12
+ class HankakuToZenkaku < ::FormKeeper::Filter::Base
13
+ def process(value)
14
+ Moji.han_to_zen(value)
15
+ end
16
+ end
17
+ class KataToHira < ::FormKeeper::Filter::Base
18
+ def process(value)
19
+ Moji.kata_to_hira(value)
20
+ end
21
+ end
22
+ class HiraToKata < ::FormKeeper::Filter::Base
23
+ def process(value)
24
+ Moji.hira_to_kata(value)
25
+ end
26
+ end
27
+ end
28
+ module Constraint
29
+ class Kana < FormKeeper::Constraint::Base
30
+ def validate(value, arg)
31
+ # TODO support ZENKAKU/HANKAKU KIGOU \p{Punct}
32
+ result = value =~ /^#{Moji.kana}+$/
33
+ result = !result if !arg
34
+ result
35
+ end
36
+ end
37
+ class Hiragana < FormKeeper::Constraint::Base
38
+ def validate(value, arg)
39
+ # TODO support ZENKAKU/HANKAKU KIGOU \p{Punct}
40
+ result = value =~ /^#{Moji.hira}+$/
41
+ result = !result if !arg
42
+ result
43
+ end
44
+ end
45
+ class Katakana < FormKeeper::Constraint::Base
46
+ def validate(value, arg)
47
+ # TODO support ZENKAKU/HANKAKU KIGOU
48
+ result = value =~ /^#{Moji.kata}+$/
49
+ result = !result if !arg
50
+ result
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ FormKeeper::Validator.register_filter :hiragana2katakana,
58
+ FormKeeper::Japanese::Filter::HiraToKata.new
59
+ FormKeeper::Validator.register_filter :katakana2hiragana,
60
+ FormKeeper::Japanese::Filter::KataToHira.new
61
+ FormKeeper::Validator.register_filter :hankaku2zenkaku,
62
+ FormKeeper::Japanese::Filter::HankakuToZenkaku.new
63
+ FormKeeper::Validator.register_filter :zenkaku2hankaku,
64
+ FormKeeper::Japanese::Filter::ZenkakuToHankaku.new
65
+ FormKeeper::Validator.register_constraint :kana,
66
+ FormKeeper::Japanese::Constraint::Kana.new
67
+ FormKeeper::Validator.register_constraint :hiragana,
68
+ FormKeeper::Japanese::Constraint::Hiragana.new
69
+ FormKeeper::Validator.register_constraint :katakana,
70
+ FormKeeper::Japanese::Constraint::Katakana.new
71
+
@@ -0,0 +1,5 @@
1
+ module FormKeeper
2
+ module Japanese
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,9 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'formkeeper'
4
+ require 'formkeeper/japanese'
5
+
6
+ RSpec.configure do |config|
7
+
8
+ end
9
+
@@ -0,0 +1,79 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe FormKeeper::Japanese do
5
+
6
+ it "validates valid params according to rule" do
7
+
8
+ rule = FormKeeper::Rule.new
9
+ rule.filters :strip
10
+ rule.field :nickname, :present => true, :kana => true, :characters => 4..8
11
+
12
+ params = {}
13
+ params['nickname'] = 'ほげほげ'
14
+
15
+ validator = FormKeeper::Validator.new
16
+ report = validator.validate(params, rule)
17
+
18
+ report.failed?.should_not be_true
19
+
20
+ report[:nickname].should == 'ほげほげ'
21
+
22
+ end
23
+
24
+ it "validates hiragana with katakana filter" do
25
+
26
+ rule = FormKeeper::Rule.new
27
+ rule.filters :hiragana2katakana
28
+ rule.field :nickname, :present => true, :kana => true, :characters => 4..8
29
+
30
+ params = {}
31
+ params['nickname'] = 'ほげほげ'
32
+
33
+ validator = FormKeeper::Validator.new
34
+ report = validator.validate(params, rule)
35
+
36
+ report.failed?.should_not be_true
37
+
38
+ report[:nickname].should == 'ホゲホゲ'
39
+
40
+ end
41
+
42
+ it "validates invalid length of hiragana" do
43
+
44
+ rule = FormKeeper::Rule.new
45
+ rule.filters :hiragana2katakana
46
+ rule.field :nickname, :present => true, :kana => true, :characters => 4..8
47
+
48
+ params = {}
49
+ params['nickname'] = 'ほげ'
50
+
51
+ validator = FormKeeper::Validator.new
52
+ report = validator.validate(params, rule)
53
+
54
+ report.failed?.should be_true
55
+
56
+ report.failed_on?(:nickname, :characters).should be_true
57
+
58
+ end
59
+
60
+ it "validates zenkaku integer" do
61
+
62
+ rule = FormKeeper::Rule.new
63
+ rule.filters :zenkaku2hankaku
64
+ rule.field :nickname, :present => true, :int => true
65
+
66
+ params = {}
67
+ params['nickname'] = '123456789'
68
+
69
+ validator = FormKeeper::Validator.new
70
+ report = validator.validate(params, rule)
71
+
72
+ report.failed?.should_not be_true
73
+
74
+ report[:nickname].should == '123456789'
75
+
76
+ end
77
+
78
+ end
79
+
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: formkeeper-japanese
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - lyokato
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-23 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: formkeeper's plugin for japanese specific filters and validators
15
+ email:
16
+ - lyo.kato@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - .rspec
23
+ - Gemfile
24
+ - LICENSE.txt
25
+ - README.md
26
+ - Rakefile
27
+ - formkeeper-japanese.gemspec
28
+ - lib/formkeeper/japanese.rb
29
+ - lib/formkeeper/japanese/version.rb
30
+ - spec/spec_helper.rb
31
+ - spec/validator_spec.rb
32
+ homepage: ''
33
+ licenses: []
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubyforge_project:
52
+ rubygems_version: 1.8.24
53
+ signing_key:
54
+ specification_version: 3
55
+ summary: This module provides you japanese specific filters and validators
56
+ test_files:
57
+ - spec/spec_helper.rb
58
+ - spec/validator_spec.rb