Class: VerEx
- Inherits:
-
Object
- Object
- VerEx
- Defined in:
- lib/ver_ex.rb,
lib/ver_ex/version.rb
Constant Summary collapse
- VERSION =
'0.0.1'
Instance Method Summary collapse
- #add(regex) ⇒ Object
- #anyOf(values) ⇒ Object
- #anything ⇒ Object
- #anythingBut(character) ⇒ Object
- #endOfLine ⇒ Object
-
#initialize(regex = '', prefix = '', postfix = '') ⇒ VerEx
constructor
A new instance of VerEx.
- #lineBreak ⇒ Object (also: #br)
- #maybe(value) ⇒ Object
- #or(value) ⇒ Object
- #regex ⇒ Object
- #sanitized(value) ⇒ Object
- #searchOneLine ⇒ Object
- #something ⇒ Object
- #somethingBut(character) ⇒ Object
- #startOfLine ⇒ Object
- #tab ⇒ Object
- #test(value) ⇒ Object
- #then(value) ⇒ Object (also: #find)
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 |
#anything ⇒ Object
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 |
#endOfLine ⇒ Object
66 67 68 |
# File 'lib/ver_ex.rb', line 66 def endOfLine VerEx.new @regex, @prefix, '$' end |
#lineBreak ⇒ Object 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 |
#regex ⇒ Object
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 |
#searchOneLine ⇒ Object
70 71 72 |
# File 'lib/ver_ex.rb', line 70 def searchOneLine VerEx.new @regex, @prefix, '$', one_line = true end |
#something ⇒ Object
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 |
#startOfLine ⇒ Object
62 63 64 |
# File 'lib/ver_ex.rb', line 62 def startOfLine VerEx.new @regex, '^', @postfix end |
#tab ⇒ Object
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 |