Class: Expect::Match
- Inherits:
-
Object
- Object
- Expect::Match
- Defined in:
- lib/expect/match.rb
Instance Attribute Summary collapse
-
#buffer ⇒ Object
readonly
Returns the value of attribute buffer.
-
#success ⇒ Object
readonly
Returns the value of attribute success.
Instance Method Summary collapse
-
#exact_match_string ⇒ Object
returns the first capture from the match.
- #expr_substring_to_match ⇒ Object
-
#initialize(expression, buffer) ⇒ Match
constructor
A new instance of Match.
-
#nil? ⇒ Boolean
true if there were no matches.
-
#substring_remainder ⇒ Object
(also: #remainder)
returns the contents of the buffer following the first match.
-
#substring_up_to_match ⇒ Object
(also: #to_s)
returns the contents of the buffer up to the match.
Constructor Details
#initialize(expression, buffer) ⇒ Match
Returns a new instance of Match.
5 6 7 8 9 |
# File 'lib/expect/match.rb', line 5 def initialize(expression, buffer) @expression = expression @buffer = buffer @matches = @buffer.match(@expression) end |
Instance Attribute Details
#buffer ⇒ Object (readonly)
Returns the value of attribute buffer.
3 4 5 |
# File 'lib/expect/match.rb', line 3 def buffer @buffer end |
#success ⇒ Object (readonly)
Returns the value of attribute success.
3 4 5 |
# File 'lib/expect/match.rb', line 3 def success @success end |
Instance Method Details
#exact_match_string ⇒ Object
returns the first capture from the match
12 13 14 |
# File 'lib/expect/match.rb', line 12 def exact_match_string @matches.nil? ? nil : @matches[0] end |
#expr_substring_to_match ⇒ Object
16 17 18 |
# File 'lib/expect/match.rb', line 16 def expr_substring_to_match Regexp.new(".*?#{@expression.source}", @expression. | Regexp::MULTILINE) end |
#nil? ⇒ Boolean
true if there were no matches
21 22 23 |
# File 'lib/expect/match.rb', line 21 def nil? @matches.nil? end |
#substring_remainder ⇒ Object Also known as: remainder
returns the contents of the buffer following the first match
32 33 34 35 36 37 38 39 |
# File 'lib/expect/match.rb', line 32 def substring_remainder if @matches.nil? @buffer else start_index = substring_up_to_match.length @buffer[start_index..-1] end end |
#substring_up_to_match ⇒ Object Also known as: to_s
returns the contents of the buffer up to the match
26 27 28 |
# File 'lib/expect/match.rb', line 26 def substring_up_to_match @matches.nil? ? nil : @buffer.match(expr_substring_to_match)[0] end |