Module: Crabfarm::Assertion::Validations
- Included in:
- Wrapper
- Defined in:
- lib/crabfarm/assertion/validations.rb
Instance Method Summary collapse
- #validate_general(_value, _options = {}) ⇒ Object
- #validate_number(_value, _options = {}) ⇒ Object
- #validate_string(_value, _options = {}) ⇒ Object
- #validate_word(_value, _options = {}) ⇒ Object
Instance Method Details
#validate_general(_value, _options = {}) ⇒ Object
22 23 24 |
# File 'lib/crabfarm/assertion/validations.rb', line 22 def validate_general _value, ={} fail_with "#{_value} is not recognized" if .key? :in and not [: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, ={} fail_with "#{_value} out of range" if .key? :greater_than and _value <= [:greater_than] fail_with "#{_value} out of range" if .key? :greater_or_equal_to and _value < [:greater_or_equal_to] fail_with "#{_value} out of range" if .key? :less_than and _value >= [:less_than] fail_with "#{_value} out of range" if .key? :less_or_equal_to and _value > [:less_or_equal_to] fail_with "#{_value} out of range" if .key? :between and not [:between].include? _value end |
#validate_string(_value, _options = {}) ⇒ Object
18 19 20 |
# File 'lib/crabfarm/assertion/validations.rb', line 18 def validate_string _value, ={} fail_with "#{_value} does not match expression" if .key? :matches and not [:matches] === _value end |
#validate_word(_value, _options = {}) ⇒ Object
13 14 15 16 |
# File 'lib/crabfarm/assertion/validations.rb', line 13 def validate_word _value, ={} fail_with "'#{_value}' is not a single word" if /\s/ === _value validate_string _value, end |