Class: Yema::Rule::Length
- Inherits:
-
Yema::Rule
- Object
- Yema::Rule
- Yema::Rule::Length
- Defined in:
- lib/yema/rule/length.rb
Instance Attribute Summary collapse
-
#length ⇒ Object
readonly
Returns the value of attribute length.
Attributes inherited from Yema::Rule
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(attribute_name, options = {}) ⇒ Length
constructor
A new instance of Length.
- #matches?(value) ⇒ Boolean
Methods inherited from Yema::Rule
Constructor Details
#initialize(attribute_name, options = {}) ⇒ Length
Returns a new instance of Length.
7 8 9 10 |
# File 'lib/yema/rule/length.rb', line 7 def initialize(attribute_name, ={}) super () end |
Instance Attribute Details
#length ⇒ Object (readonly)
Returns the value of attribute length.
5 6 7 |
# File 'lib/yema/rule/length.rb', line 5 def length @length end |
Class Method Details
.required_options ⇒ Object
12 13 14 |
# File 'lib/yema/rule/length.rb', line 12 def self. [:length] end |
Instance Method Details
#matches?(value) ⇒ Boolean
16 17 18 19 20 21 22 23 |
# File 'lib/yema/rule/length.rb', line 16 def matches?(value) raise ArgumentError unless value.respond_to?(:length) case length when Range; length.include?(value.length) when Fixnum; length == value.length end end |