Class: Travis::Conditions::V1::Regex

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/travis/conditions/v1/regex.rb

Constant Summary collapse

REGEX =
%r(\S*[^\s\)]+)
DELIM =
'/'
ESC =
'\\'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ Regex

Returns a new instance of Regex.



17
18
19
20
# File 'lib/travis/conditions/v1/regex.rb', line 17

def initialize(str)
  @str = StringScanner.new(str.to_s.strip)
  @esc = false
end

Instance Attribute Details

#strObject (readonly)

Returns the value of attribute str.



15
16
17
# File 'lib/travis/conditions/v1/regex.rb', line 15

def str
  @str
end

Instance Method Details

#readObject



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/travis/conditions/v1/regex.rb', line 39

def read
  char = peek(1)
  if char == DELIM && !@esc
    :eos
  elsif char == ESC
    @esc = true
    getch
  else
    @esc = false
    getch
  end
end

#regexObject



31
32
33
34
35
36
37
# File 'lib/travis/conditions/v1/regex.rb', line 31

def regex
  return unless peek(1) == DELIM && reg = getch
  char = nil
  reg << char while (char = read) && char != :eos
  reg << DELIM if char == :eos
  reg unless reg.empty?
end

#scanObject



22
23
24
# File 'lib/travis/conditions/v1/regex.rb', line 22

def scan
  word || regex
end

#wordObject



26
27
28
29
# File 'lib/travis/conditions/v1/regex.rb', line 26

def word
  return if peek(1) == DELIM
  str.scan(REGEX)
end