Module: Crabfarm::Assertion::Validations

Included in:
Wrapper
Defined in:
lib/crabfarm/assertion/validations.rb

Instance Method Summary collapse

Instance Method Details

#validate_general(_value, _options = {}) ⇒ Object



22
23
24
# File 'lib/crabfarm/assertion/validations.rb', line 22

def validate_general _value, _options={}
  fail_with "#{_value} is not recognized" if _options.key? :in and not _options[:in].include? _value
end

#validate_number(_value, _options = {}) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/crabfarm/assertion/validations.rb', line 5

def validate_number _value, _options={}
  fail_with "#{_value} out of range" if _options.key? :greater_than and _value <= _options[:greater_than]
  fail_with "#{_value} out of range" if _options.key? :greater_or_equal_to and _value < _options[:greater_or_equal_to]
  fail_with "#{_value} out of range" if _options.key? :less_than and _value >= _options[:less_than]
  fail_with "#{_value} out of range" if _options.key? :less_or_equal_to and _value > _options[:less_or_equal_to]
  fail_with "#{_value} out of range" if _options.key? :between and not _options[:between].include? _value
end

#validate_string(_value, _options = {}) ⇒ Object



18
19
20
# File 'lib/crabfarm/assertion/validations.rb', line 18

def validate_string _value, _options={}
  fail_with "#{_value} does not match expression" if _options.key? :matches and not _options[:matches] === _value
end

#validate_word(_value, _options = {}) ⇒ Object



13
14
15
16
# File 'lib/crabfarm/assertion/validations.rb', line 13

def validate_word _value, _options={}
  fail_with "'#{_value}' is not a single word" if /\s/ === _value
  validate_string _value, _options
end