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
- #expr_substring_to_match ⇒ Object
-
#initialize(expression, buffer) ⇒ Match
constructor
A new instance of Match.
- #nil? ⇒ Boolean
- #substring_remainder ⇒ Object (also: #remainder)
- #substring_up_to_match ⇒ Object (also: #to_s)
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
11 12 13 |
# File 'lib/expect/match.rb', line 11 def exact_match_string @matches.nil? ? nil : @matches[0] end |
#expr_substring_to_match ⇒ Object
15 16 17 |
# File 'lib/expect/match.rb', line 15 def expr_substring_to_match Regexp.new(".*?#{@expression.source}", @expression. | Regexp::MULTILINE) end |
#nil? ⇒ Boolean
19 20 21 |
# File 'lib/expect/match.rb', line 19 def nil? @matches.nil? end |
#substring_remainder ⇒ Object Also known as: remainder
28 29 30 31 32 33 34 35 |
# File 'lib/expect/match.rb', line 28 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
23 24 25 |
# File 'lib/expect/match.rb', line 23 def substring_up_to_match @matches.nil? ? nil : @buffer.match(expr_substring_to_match)[0] end |