Class: Moon::Validator::Length
- Inherits:
-
Object
- Object
- Moon::Validator::Length
- Defined in:
- lib/moon/validator/length.rb
Overview
Value length validator.
Instance Method Summary collapse
-
#initialize(range) ⇒ Length
constructor
A new instance of Length.
- #messages(value, context) ⇒ Object
Constructor Details
#initialize(range) ⇒ Length
Returns a new instance of Length.
5 6 7 |
# File 'lib/moon/validator/length.rb', line 5 def initialize(range) @range = range end |
Instance Method Details
#messages(value, context) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/moon/validator/length.rb', line 9 def (value, context) raise ArgumentError, "Value doesn't response to :size" unless value.respond_to?(:size) size, minimum, maximum = value.size, @range.min, @range.max @range.include?(size) ? [ ] : [ "Must have at #{size < minimum ? ("least " + minimum.to_s) : ("most " + maximum.to_s)} entries." ] end |