Class: Expect::Match

Inherits:
Object
  • Object
show all
Defined in:
lib/expect/match.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#bufferObject (readonly)

Returns the value of attribute buffer.



3
4
5
# File 'lib/expect/match.rb', line 3

def buffer
  @buffer
end

#successObject (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_stringObject

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_matchObject



16
17
18
# File 'lib/expect/match.rb', line 16

def expr_substring_to_match
  Regexp.new(".*?#{@expression.source}", @expression.options | Regexp::MULTILINE)
end

#nil?Boolean

true if there were no matches

Returns:

  • (Boolean)


21
22
23
# File 'lib/expect/match.rb', line 21

def nil?
  @matches.nil?
end

#substring_remainderObject 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_matchObject 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