formkeeper 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module FormKeeper
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
data/lib/formkeeper.rb CHANGED
@@ -61,6 +61,12 @@ module FormKeeper
61
61
  return value.strip
62
62
  end
63
63
  end
64
+
65
+ class Capitalize < Base
66
+ def process(value)
67
+ return value.capitalize
68
+ end
69
+ end
64
70
  end
65
71
 
66
72
  module Constraint
@@ -106,16 +112,84 @@ module FormKeeper
106
112
  class Int < Base
107
113
  def validate(value, arg)
108
114
  result = value =~ /^\-?[[:digit:]]+$/
109
- result = !result if !arg
110
- result
115
+ if result and arg.kind_of?(Hash)
116
+ if arg.has_key?(:gt)
117
+ unless arg[:gt].kind_of?(Fixnum)
118
+ raise ArgumentError.new ':gt should be Fixnum'
119
+ end
120
+ return false unless value.to_i > arg[:gt];
121
+ end
122
+ if arg.has_key?(:gte)
123
+ unless arg[:gte].kind_of?(Fixnum)
124
+ raise ArgumentError.new ':gte should be Fixnum'
125
+ end
126
+ return false unless value.to_i >= arg[:gte];
127
+ end
128
+ if arg.has_key?(:lt)
129
+ unless arg[:lt].kind_of?(Fixnum)
130
+ raise ArgumentError.new ':lt should be Fixnum'
131
+ end
132
+ return false unless value.to_i < arg[:lt];
133
+ end
134
+ if arg.has_key?(:lte)
135
+ unless arg[:lte].kind_of?(Fixnum)
136
+ raise ArgumentError.new ':lte should be Fixnum'
137
+ end
138
+ return false unless value.to_i <= arg[:lte];
139
+ end
140
+ if arg.has_key?(:between)
141
+ unless arg[:between].kind_of?(Range)
142
+ raise ArgumentError.new ':between should be Range'
143
+ end
144
+ return false unless arg[:between].include?(value.to_i);
145
+ end
146
+ true
147
+ else
148
+ result = !result if !arg
149
+ result
150
+ end
111
151
  end
112
152
  end
113
153
 
114
154
  class Uint < Base
115
155
  def validate(value, arg)
116
156
  result = value =~ /^[[:digit:]]+$/
117
- result = !result if !arg
118
- result
157
+ if result and arg.kind_of?(Hash)
158
+ if arg.has_key?(:gt)
159
+ unless arg[:gt].kind_of?(Fixnum)
160
+ raise ArgumentError.new ':gt should be Fixnum'
161
+ end
162
+ return false unless value.to_i > arg[:gt];
163
+ end
164
+ if arg.has_key?(:gte)
165
+ unless arg[:gte].kind_of?(Fixnum)
166
+ raise ArgumentError.new ':gte should be Fixnum'
167
+ end
168
+ return false unless value.to_i >= arg[:gte];
169
+ end
170
+ if arg.has_key?(:lt)
171
+ unless arg[:lt].kind_of?(Fixnum)
172
+ raise ArgumentError.new ':lt should be Fixnum'
173
+ end
174
+ return false unless value.to_i < arg[:lt];
175
+ end
176
+ if arg.has_key?(:lte)
177
+ unless arg[:lte].kind_of?(Fixnum)
178
+ raise ArgumentError.new ':lte should be Fixnum'
179
+ end
180
+ return false unless value.to_i <= arg[:lte];
181
+ end
182
+ if arg.has_key?(:between)
183
+ unless arg[:between].kind_of?(Range)
184
+ raise ArgumentError.new ':between should be Range'
185
+ end
186
+ return false unless arg[:between].include?(value.to_i);
187
+ end
188
+ true
189
+ else
190
+ result = !result if !arg
191
+ result
192
+ end
119
193
  end
120
194
  end
121
195
 
@@ -573,6 +647,7 @@ module FormKeeper
573
647
  register_filter :strip, Filter::Strip.new
574
648
  register_filter :downcase, Filter::DownCase.new
575
649
  register_filter :upcase, Filter::UpCase.new
650
+ register_filter :capitalize, Filter::Capitalize.new
576
651
 
577
652
  register_constraint :ascii, Constraint::Ascii.new
578
653
  register_constraint :ascii_space, Constraint::AsciiSpace.new
@@ -13,6 +13,14 @@ describe FormKeeper::Constraint::Int do
13
13
  constraint.validate('-1111', true).should be_true
14
14
  constraint.validate('-1111', false).should_not be_true
15
15
 
16
+ constraint.validate('1111', {:gt => 111}).should be_true
17
+ constraint.validate('1111', {:gt => 2222}).should_not be_true
18
+ constraint.validate('1111', {:gt => 111, :lte => 1111}).should be_true
19
+ constraint.validate('1111', {:gt => 111, :lt => 1111}).should_not be_true
20
+ constraint.validate('1111', {:gt => 111, :lt => 1112}).should be_true
21
+ constraint.validate('1111', {:gte => 1111, :lte => 1111}).should be_true
22
+ constraint.validate('1111', {:between => 1110..1112}).should be_true
23
+ constraint.validate('1111', {:between => 1113..1115}).should_not be_true
16
24
  end
17
25
 
18
26
  end
@@ -13,6 +13,15 @@ describe FormKeeper::Constraint::Uint do
13
13
  constraint.validate('-1111', true).should_not be_true
14
14
  constraint.validate('-1111', false).should be_true
15
15
 
16
+ constraint.validate('1111', {:gt => 111}).should be_true
17
+ constraint.validate('1111', {:gt => 2222}).should_not be_true
18
+ constraint.validate('1111', {:gt => 111, :lte => 1111}).should be_true
19
+ constraint.validate('1111', {:gt => 111, :lt => 1111}).should_not be_true
20
+ constraint.validate('1111', {:gt => 111, :lt => 1112}).should be_true
21
+ constraint.validate('1111', {:gte => 1111, :lte => 1111}).should be_true
22
+ constraint.validate('1111', {:between => 1110..1112}).should be_true
23
+ constraint.validate('1111', {:between => 1113..1115}).should_not be_true
24
+
16
25
  end
17
26
 
18
27
  end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe FormKeeper::Filter::Capitalize do
4
+
5
+ it "filters value correctly" do
6
+ filter = FormKeeper::Filter::Capitalize.new
7
+ filter.process("FOO").should == "Foo";
8
+ filter.process("fOO").should == "Foo";
9
+ filter.process("foo").should == "Foo";
10
+ filter.process(" foo").should == " foo";
11
+ end
12
+
13
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formkeeper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -45,6 +45,7 @@ files:
45
45
  - spec/constraint_regexp_spec.rb
46
46
  - spec/constraint_uint_spec.rb
47
47
  - spec/constraint_uri_spec.rb
48
+ - spec/filter_capitalize_spec.rb
48
49
  - spec/filter_downcase_spec.rb
49
50
  - spec/filter_strip_spec.rb
50
51
  - spec/filter_upcase_spec.rb
@@ -69,7 +70,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
69
70
  version: '0'
70
71
  segments:
71
72
  - 0
72
- hash: 356989708151318593
73
+ hash: -3327834832335453683
73
74
  required_rubygems_version: !ruby/object:Gem::Requirement
74
75
  none: false
75
76
  requirements:
@@ -78,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
79
  version: '0'
79
80
  segments:
80
81
  - 0
81
- hash: 356989708151318593
82
+ hash: -3327834832335453683
82
83
  requirements: []
83
84
  rubyforge_project:
84
85
  rubygems_version: 1.8.24
@@ -104,6 +105,7 @@ test_files:
104
105
  - spec/constraint_regexp_spec.rb
105
106
  - spec/constraint_uint_spec.rb
106
107
  - spec/constraint_uri_spec.rb
108
+ - spec/filter_capitalize_spec.rb
107
109
  - spec/filter_downcase_spec.rb
108
110
  - spec/filter_strip_spec.rb
109
111
  - spec/filter_upcase_spec.rb