Class: Perpetuity::Validations::Length
- Inherits:
-
Object
- Object
- Perpetuity::Validations::Length
- Defined in:
- lib/perpetuity/validations/length.rb
Instance Method Summary collapse
- #at_least(value) ⇒ Object
- #at_most(value) ⇒ Object
- #between(range) ⇒ Object
-
#initialize(attribute, options) ⇒ Length
constructor
A new instance of Length.
- #pass?(object) ⇒ Boolean
Constructor Details
#initialize(attribute, options) ⇒ Length
Returns a new instance of Length.
4 5 6 7 8 9 10 11 |
# File 'lib/perpetuity/validations/length.rb', line 4 def initialize attribute, @attribute = attribute @at_least = nil @at_most = nil .each do |option, value| send option, value end end |
Instance Method Details
#at_least(value) ⇒ Object
22 23 24 |
# File 'lib/perpetuity/validations/length.rb', line 22 def at_least value @at_least = value end |
#at_most(value) ⇒ Object
26 27 28 |
# File 'lib/perpetuity/validations/length.rb', line 26 def at_most value @at_most = value end |
#between(range) ⇒ Object
30 31 32 33 |
# File 'lib/perpetuity/validations/length.rb', line 30 def between range at_least range.min at_most range.max end |
#pass?(object) ⇒ Boolean
13 14 15 16 17 18 19 20 |
# File 'lib/perpetuity/validations/length.rb', line 13 def pass? object length = object.send(@attribute).length return false unless @at_least.nil? or @at_least <= length return false unless @at_most.nil? or @at_most >= length true end |