Class: StringRule
Instance Attribute Summary collapse
-
#max_length ⇒ Object
Returns the value of attribute max_length.
-
#min_length ⇒ Object
Returns the value of attribute min_length.
Instance Method Summary collapse
-
#initialize ⇒ StringRule
constructor
A new instance of StringRule.
- #result ⇒ Object
- #test(value) ⇒ Object
- #train(meta) ⇒ Object
Constructor Details
#initialize ⇒ StringRule
Returns a new instance of StringRule.
8 9 10 11 12 13 |
# File 'lib/rules/StringRule.rb', line 8 def initialize() @min_length = nil @max_length = nil end |
Instance Attribute Details
#max_length ⇒ Object
Returns the value of attribute max_length.
6 7 8 |
# File 'lib/rules/StringRule.rb', line 6 def max_length @max_length end |
#min_length ⇒ Object
Returns the value of attribute min_length.
5 6 7 |
# File 'lib/rules/StringRule.rb', line 5 def min_length @min_length end |
Instance Method Details
#result ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/rules/StringRule.rb', line 49 def result() { :type => :string, :min_length => @min_length, :max_length => @max_length } end |
#test(value) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/rules/StringRule.rb', line 39 def test(value) length = value.length return false if length < @min_length return false if length > @max_length true end |
#train(meta) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rules/StringRule.rb', line 18 def train() length = [:length] if @min_length.nil? @min_length = length else @min_length = length if length < @min_length end if @max_length.nil? @max_length = length else @max_length = length if length > @max_length end end |