Module: Crabfarm::Assertion::Validations
- Included in:
- Wrapper
- Defined in:
- lib/crabfarm/assertion/validations.rb
Instance Method Summary collapse
- #validate_general(_value, _options = {}, &_block) ⇒ Object
- #validate_number(_value, _options = {}) ⇒ Object
- #validate_string(_value, _options = {}) ⇒ Object
- #validate_word(_value, _options = {}) ⇒ Object
Instance Method Details
#validate_general(_value, _options = {}, &_block) ⇒ Object
23 24 25 26 |
# File 'lib/crabfarm/assertion/validations.rb', line 23 def validate_general _value, ={}, &_block fail_with "#{_value} is not recognized" if .key? :in and not [:in].include? _value fail_with "#{_value} is not valid" if _block and !_block.call(_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 21 |
# 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 fail_with "#{_value} does not contain substring" if .key? :contains and !_value.include? [:contains] 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 |