Class: Crabfarm::Assertion::Wrapper
- Inherits:
-
Object
- Object
- Crabfarm::Assertion::Wrapper
show all
- Includes:
- Parsers, Validations
- Defined in:
- lib/crabfarm/assertion/wrapper.rb
Instance Method Summary
collapse
#validate_general, #validate_number, #validate_string, #validate_word
Methods included from Parsers
#clean_string, #extract_number_from_string, #fail_with_nil, #infer_thousand_separator, #parse_boolean, #parse_by_map, #parse_float, #parse_integer, #parse_number, #parse_phrase, #return_default
Constructor Details
#initialize(_value, _context = nil) ⇒ Wrapper
Returns a new instance of Wrapper.
10
11
12
13
14
15
16
|
# File 'lib/crabfarm/assertion/wrapper.rb', line 10
def initialize(_value, _context=nil)
@value = if _value.respond_to? :text
_value.text
else _value end
@context = _context
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(_method, *_args) ⇒ Object
73
74
75
76
77
|
# File 'lib/crabfarm/assertion/wrapper.rb', line 73
def method_missing(_method, *_args)
if @value.respond_to? :method
@value = @value.send(*_args)
else super end
end
|
Instance Method Details
#is_boolean(_options = {}) ⇒ Object
Also known as:
is_b
57
58
59
60
61
|
# File 'lib/crabfarm/assertion/wrapper.rb', line 57
def is_boolean(_options={})
perform_assertion(_options) {
@value = parse_boolean @value, _options
}
end
|
#is_float(_options = {}) ⇒ Object
Also known as:
is_f
28
29
30
31
32
33
34
|
# File 'lib/crabfarm/assertion/wrapper.rb', line 28
def is_float(_options={})
perform_assertion(_options) {
@value = parse_float @value, _options
validate_number @value, _options
validate_general @value, _options
}
end
|
#is_integer(_options = {}) ⇒ Object
Also known as:
is_i
18
19
20
21
22
23
24
|
# File 'lib/crabfarm/assertion/wrapper.rb', line 18
def is_integer(_options={})
perform_assertion(_options) {
@value = parse_integer @value, _options
validate_number @value, _options
validate_general @value, _options
}
end
|
#is_string(_options = {}) ⇒ Object
Also known as:
is_s
47
48
49
50
51
52
53
|
# File 'lib/crabfarm/assertion/wrapper.rb', line 47
def is_string(_options={})
perform_assertion(_options) {
@value = parse_phrase @value, _options
validate_string @value, _options
validate_general @value, _options
}
end
|
#is_word(_options = {}) ⇒ Object
Also known as:
is_w
38
39
40
41
42
43
44
|
# File 'lib/crabfarm/assertion/wrapper.rb', line 38
def is_word(_options={})
perform_assertion(_options) {
@value = parse_phrase @value, _options
validate_word @value, _options
validate_general @value, _options
}
end
|
#matches(_rgx, _options = {}) ⇒ Object
65
66
67
68
69
70
71
|
# File 'lib/crabfarm/assertion/wrapper.rb', line 65
def matches(_rgx, _options={})
perform_assertion(_options) {
match = _rgx.match @value
fail_with "#{@value} does not match #{_rgx.to_s}" if match.nil?
match
}
end
|
#respond_to?(*args) ⇒ Boolean
79
80
81
|
# File 'lib/crabfarm/assertion/wrapper.rb', line 79
def respond_to?(*args)
@value.respond_to?(*args)
end
|