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



11
12
13
# File 'lib/expect/match.rb', line 11

def exact_match_string
  @matches.nil? ? nil : @matches[0]
end

#expr_substring_to_matchObject



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

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

#nil?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/expect/match.rb', line 19

def nil?
  @matches.nil?
end

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