Class: VerEx

Inherits:
Object
  • Object
show all
Defined in:
lib/ver_ex.rb,
lib/ver_ex/version.rb

Constant Summary collapse

VERSION =
'0.0.1'

Instance Method Summary collapse

Constructor Details

#initialize(regex = '', prefix = '', postfix = '') ⇒ VerEx



2
3
4
5
6
# File 'lib/ver_ex.rb', line 2

def initialize regex='', prefix='', postfix=''
  @regex = regex
  @prefix = prefix
  @postfix = postfix
end

Instance Method Details

#add(regex) ⇒ Object



74
75
76
# File 'lib/ver_ex.rb', line 74

def add regex
  VerEx.new @regex + regex, @prefix, @postfix
end

#anyOf(values) ⇒ Object



33
34
35
# File 'lib/ver_ex.rb', line 33

def anyOf values
  add "(?:[#{values}]+)"
end

#anythingObject



12
13
14
# File 'lib/ver_ex.rb', line 12

def anything
  add '(?:.*)'
end

#anythingBut(character) ⇒ Object



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

def anythingBut character
  add "(?:[^#{character}]*)"
end

#endOfLineObject



66
67
68
# File 'lib/ver_ex.rb', line 66

def endOfLine
  VerEx.new @regex, @prefix, '$'
end

#lineBreakObject Also known as: br



57
58
59
# File 'lib/ver_ex.rb', line 57

def lineBreak
  maybe("\r").then("\n")
end

#maybe(value) ⇒ Object



29
30
31
# File 'lib/ver_ex.rb', line 29

def maybe value
  add "(?:#{value})?"
end

#or(value) ⇒ Object



45
46
47
# File 'lib/ver_ex.rb', line 45

def or value
  VerEx.new "(?:#{@regex})|(?:#{sanitized(value)})", @prefix, @postfix
end

#regexObject



41
42
43
# File 'lib/ver_ex.rb', line 41

def regex
  Regexp.new(@prefix + "(?:" +  @regex + ")" + @postfix)
end

#sanitized(value) ⇒ Object



53
54
55
# File 'lib/ver_ex.rb', line 53

def sanitized value
  Regexp.quote value
end

#searchOneLineObject



70
71
72
# File 'lib/ver_ex.rb', line 70

def searchOneLine
  VerEx.new @regex, @prefix, '$', one_line = true
end

#somethingObject



8
9
10
# File 'lib/ver_ex.rb', line 8

def something
  add '(?:.+)'
end

#somethingBut(character) ⇒ Object



20
21
22
# File 'lib/ver_ex.rb', line 20

def somethingBut character
  add "(?:[^#{character}]+)"
end

#startOfLineObject



62
63
64
# File 'lib/ver_ex.rb', line 62

def startOfLine
  VerEx.new @regex, '^', @postfix
end

#tabObject



49
50
51
# File 'lib/ver_ex.rb', line 49

def tab
  add '\t'
end

#test(value) ⇒ Object



37
38
39
# File 'lib/ver_ex.rb', line 37

def test value
  !!regex.match(value)
end

#then(value) ⇒ Object Also known as: find



24
25
26
# File 'lib/ver_ex.rb', line 24

def then value
  add sanitized(value)
end