Class: Regexp

Inherits:
Object show all
Extended by:
Assertions::ClassMethods, ClassMethods
Includes:
Assertions, Constants
Defined in:
app/models/regexp.rb

Overview

Copyright (C) 2013 by Greg Lawson

<[email protected]>

Copyright: See COPYING file that comes with this distribution

Defined Under Namespace

Modules: Assertions, ClassMethods, Constants, Examples

Constant Summary

Constants included from Constants

Constants::Any, Constants::Any_binary_char_string, Constants::Default_options, Constants::End_string, Constants::End_string_less_newline, Constants::Many, Constants::Optional, Constants::Start_string

Instance Method Summary collapse

Methods included from Assertions::ClassMethods

assert_post_conditions, assert_pre_conditions

Methods included from ClassMethods

delimiter_regexp, promote, regexp_error, regexp_rescued, terminator_regexp

Methods included from Assertions

#assert_post_conditions, #assert_pre_conditions

Instance Method Details

#*(other) ⇒ Object

unescape


61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/models/regexp.rb', line 61

def *(other)
	case other
	when Regexp then return Regexp.new(self.source + other.source)
	when String then return Regexp.new(self.source + other)
	when Fixnum then return Regexp.new(self.source*other)
	when NilClass then raise "Right argument of :* operator evaluated to nil."+
		"\nPossibly add parenthesis to control operator versus method precedence."+
		"\nIn order to evaluate left to right, place parenthesis around operator expressions."
		"\nself=#{self.inspect}"
	else
		raise "other.class=#{other.class.inspect}"
	end #case
end

#back_reference(key) ⇒ Object

capture backreferences must be all numbered or all named.


85
86
87
88
89
90
91
# File 'app/models/regexp.rb', line 85

def back_reference(key)
		/#{self.source}\k<#{key.to_s}>/
rescue RegexpError => exception
	warn "back_reference regexp=/#{self.source}\k<#{key.to_s}>/ failed."+
		"\nPossibly add parenthesis to control operator versus method precedence."+
		"\nIn order to evaluate left to right, place parenthesis around operator expressions."
end

#capture(key = nil) ⇒ Object

alterative


77
78
79
80
81
82
83
# File 'app/models/regexp.rb', line 77

def capture(key=nil)
	if key.nil? then
		/(#{self.source})/
	else
		/(?<#{key.to_s}>#{self.source})/
	end #if
end

#groupObject

back_reference


92
93
94
# File 'app/models/regexp.rb', line 92

def group
	/(?:#{self.source})/
end

#unescaped_stringObject


58
59
60
# File 'app/models/regexp.rb', line 58

def unescaped_string
	"#{source}"
end

#|(other) ⇒ Object

sequence


74
75
76
# File 'app/models/regexp.rb', line 74

def |(other) # |
	return Regexp.union(self.source, Regexp.promote(other).source)
end