formkeeper-japanese 0.0.1 → 0.0.2

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/Gemfile CHANGED
@@ -6,7 +6,7 @@ gemspec
6
6
  gem "hpricot"
7
7
  gem "rack"
8
8
  gem "moji"
9
- gem "formkeeper", "~> 0.0.4"
9
+ gem "formkeeper", "~> 0.0.12"
10
10
 
11
11
  group :development, :test do
12
12
  gem "rspec"
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # FormKeeper::Japanese
2
2
 
3
- TODO: Write a gem description
3
+ This provides Japanese specific filters and constraints for formkeeper
4
4
 
5
5
  ## Installation
6
6
 
@@ -18,7 +18,40 @@ Or install it yourself as:
18
18
 
19
19
  ## Usage
20
20
 
21
- TODO: Write usage instructions here
21
+ ### Synopsis
22
+
23
+ In your sinatra application with sinatra-formkeeper
24
+
25
+ ```ruby
26
+ require 'sinatra/formkeeper'
27
+ require 'formkeeper/japanese'
28
+
29
+ post '/entry' do
30
+ form do
31
+ field :yomigana, :present => true, :katakana => true, :length => 0..16 :filters => [:hiragana_to_katakana]
32
+ field :tel, :present => true, :int => true, :filters => [:zenkaku_to_hankaku]
33
+ end
34
+ end
35
+
36
+ ```
37
+
38
+ ### Filters
39
+
40
+ * zenkaku_to_hankaku
41
+ * hankaku_to_zenkaku
42
+ * hiragana_to_katakana
43
+ * katakana_to_hiragana
44
+
45
+ ### Constraints
46
+
47
+ * kana
48
+ * hiragana
49
+ * katakana
50
+
51
+ ## See Also
52
+
53
+ * https://github.com/lyokato/formkeeper
54
+ * https://github.com/lyokato/sinatra-formkeeper
22
55
 
23
56
  ## Contributing
24
57
 
@@ -4,6 +4,7 @@ require "moji"
4
4
  module FormKeeper
5
5
  module Japanese
6
6
  module Filter
7
+
7
8
  class ZenkakuToHankaku < ::FormKeeper::Filter::Base
8
9
  def process(value)
9
10
  Moji.zen_to_han(value)
@@ -28,7 +29,6 @@ module FormKeeper
28
29
  module Constraint
29
30
  class Kana < FormKeeper::Constraint::Base
30
31
  def validate(value, arg)
31
- # TODO support ZENKAKU/HANKAKU KIGOU \p{Punct}
32
32
  result = value =~ /^#{Moji.kana}+$/
33
33
  result = !result if !arg
34
34
  result
@@ -36,7 +36,6 @@ module FormKeeper
36
36
  end
37
37
  class Hiragana < FormKeeper::Constraint::Base
38
38
  def validate(value, arg)
39
- # TODO support ZENKAKU/HANKAKU KIGOU \p{Punct}
40
39
  result = value =~ /^#{Moji.hira}+$/
41
40
  result = !result if !arg
42
41
  result
@@ -44,7 +43,6 @@ module FormKeeper
44
43
  end
45
44
  class Katakana < FormKeeper::Constraint::Base
46
45
  def validate(value, arg)
47
- # TODO support ZENKAKU/HANKAKU KIGOU
48
46
  result = value =~ /^#{Moji.kata}+$/
49
47
  result = !result if !arg
50
48
  result
@@ -54,13 +52,13 @@ module FormKeeper
54
52
  end
55
53
  end
56
54
 
57
- FormKeeper::Validator.register_filter :hiragana2katakana,
55
+ FormKeeper::Validator.register_filter :hiragana_to_katakana,
58
56
  FormKeeper::Japanese::Filter::HiraToKata.new
59
- FormKeeper::Validator.register_filter :katakana2hiragana,
57
+ FormKeeper::Validator.register_filter :katakana_to_hiragana,
60
58
  FormKeeper::Japanese::Filter::KataToHira.new
61
- FormKeeper::Validator.register_filter :hankaku2zenkaku,
59
+ FormKeeper::Validator.register_filter :hankaku_to_zenkaku,
62
60
  FormKeeper::Japanese::Filter::HankakuToZenkaku.new
63
- FormKeeper::Validator.register_filter :zenkaku2hankaku,
61
+ FormKeeper::Validator.register_filter :zenkaku_to_hankaku,
64
62
  FormKeeper::Japanese::Filter::ZenkakuToHankaku.new
65
63
  FormKeeper::Validator.register_constraint :kana,
66
64
  FormKeeper::Japanese::Constraint::Kana.new
@@ -1,5 +1,5 @@
1
1
  module FormKeeper
2
2
  module Japanese
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -7,7 +7,7 @@ describe FormKeeper::Japanese do
7
7
 
8
8
  rule = FormKeeper::Rule.new
9
9
  rule.filters :strip
10
- rule.field :nickname, :present => true, :kana => true, :characters => 4..8
10
+ rule.field :nickname, :present => true, :kana => true, :length => 4..8
11
11
 
12
12
  params = {}
13
13
  params['nickname'] = 'ほげほげ'
@@ -24,8 +24,8 @@ describe FormKeeper::Japanese do
24
24
  it "validates hiragana with katakana filter" do
25
25
 
26
26
  rule = FormKeeper::Rule.new
27
- rule.filters :hiragana2katakana
28
- rule.field :nickname, :present => true, :kana => true, :characters => 4..8
27
+ rule.filters :hiragana_to_katakana
28
+ rule.field :nickname, :present => true, :kana => true, :length => 4..8
29
29
 
30
30
  params = {}
31
31
  params['nickname'] = 'ほげほげ'
@@ -39,11 +39,57 @@ describe FormKeeper::Japanese do
39
39
 
40
40
  end
41
41
 
42
+ it "validates katakana with hiragana filter" do
43
+
44
+ rule = FormKeeper::Rule.new
45
+ rule.filters :katakana_to_hiragana
46
+ rule.field :nickname, :present => true, :kana => true, :length => 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_not be_true
55
+
56
+ report[:nickname].should == 'ほげほげ'
57
+
58
+ end
59
+
60
+ it "validates valid kana filter" do
61
+
62
+ rule = FormKeeper::Rule.new
63
+ rule.field :value01, :present => true, :hiragana => true, :length => 4..8
64
+ rule.field :value02, :present => true, :hiragana => true, :length => 4..8
65
+ rule.field :value03, :present => true, :katakana => true, :length => 4..8
66
+ rule.field :value04, :present => true, :katakana => true, :length => 4..8
67
+
68
+ params = {}
69
+ params['value01'] = 'ほげほげ'
70
+ params['value02'] = 'ホゲホゲ'
71
+ params['value03'] = 'ほげほげ'
72
+ params['value04'] = 'ホゲホゲ'
73
+
74
+ validator = FormKeeper::Validator.new
75
+ report = validator.validate(params, rule)
76
+
77
+ report.failed?.should be_true
78
+
79
+ report.failed_on?(:value02, :hiragana).should be_true
80
+ report.failed_on?(:value03, :katakana).should be_true
81
+
82
+ report[:value01].should == 'ほげほげ'
83
+ report[:value04].should == 'ホゲホゲ'
84
+
85
+ end
86
+
87
+
42
88
  it "validates invalid length of hiragana" do
43
89
 
44
90
  rule = FormKeeper::Rule.new
45
- rule.filters :hiragana2katakana
46
- rule.field :nickname, :present => true, :kana => true, :characters => 4..8
91
+ rule.filters :hiragana_to_katakana
92
+ rule.field :nickname, :present => true, :kana => true, :length => 4..8
47
93
 
48
94
  params = {}
49
95
  params['nickname'] = 'ほげ'
@@ -53,14 +99,14 @@ describe FormKeeper::Japanese do
53
99
 
54
100
  report.failed?.should be_true
55
101
 
56
- report.failed_on?(:nickname, :characters).should be_true
102
+ report.failed_on?(:nickname, :length).should be_true
57
103
 
58
104
  end
59
105
 
60
106
  it "validates zenkaku integer" do
61
107
 
62
108
  rule = FormKeeper::Rule.new
63
- rule.filters :zenkaku2hankaku
109
+ rule.filters :zenkaku_to_hankaku
64
110
  rule.field :nickname, :present => true, :int => true
65
111
 
66
112
  params = {}
@@ -75,5 +121,23 @@ describe FormKeeper::Japanese do
75
121
 
76
122
  end
77
123
 
124
+ it "validates hankaku integer" do
125
+
126
+ rule = FormKeeper::Rule.new
127
+ rule.filters :hankaku_to_zenkaku
128
+ rule.field :nickname, :present => true, :int => true
129
+
130
+ params = {}
131
+ params['nickname'] = '123456789'
132
+
133
+ validator = FormKeeper::Validator.new
134
+ report = validator.validate(params, rule)
135
+
136
+ report.failed?.should_not be_true
137
+
138
+ report[:nickname].should == '123456789'
139
+
140
+ end
141
+
78
142
  end
79
143
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formkeeper-japanese
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-23 00:00:00.000000000 Z
12
+ date: 2012-10-26 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: formkeeper's plugin for japanese specific filters and validators
15
15
  email:
@@ -41,12 +41,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
41
41
  - - ! '>='
42
42
  - !ruby/object:Gem::Version
43
43
  version: '0'
44
+ segments:
45
+ - 0
46
+ hash: -519163813347447336
44
47
  required_rubygems_version: !ruby/object:Gem::Requirement
45
48
  none: false
46
49
  requirements:
47
50
  - - ! '>='
48
51
  - !ruby/object:Gem::Version
49
52
  version: '0'
53
+ segments:
54
+ - 0
55
+ hash: -519163813347447336
50
56
  requirements: []
51
57
  rubyforge_project:
52
58
  rubygems_version: 1.8.24