Class: RegExpr::Segment

Inherits:
Object
  • Object
show all
Defined in:
lib/regexpr.rb

Overview

any thing

Direct Known Subclasses

Begin, Block, Char, Chars, End, Not, Or, Range, Regexp, Repeat, WildCard

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(val) ⇒ Segment

Returns a new instance of Segment.



8
# File 'lib/regexpr.rb', line 8

def initialize( val) self.value= val end

Instance Attribute Details

#valueObject

Returns the value of attribute value.



7
8
9
# File 'lib/regexpr.rb', line 7

def value
  @value
end

Class Method Details

.deepestObject

can’t have any segment as value



27
28
29
30
31
# File 'lib/regexpr.rb', line 27

def deepest
	self.class_eval do
		def names() [] end
	end
end

.nooptimizeObject



43
44
45
46
47
# File 'lib/regexpr.rb', line 43

def nooptimize
	self.class_eval do
		def optimize() self end
	end
end

.novalueObject

can’t have any value



34
35
36
37
38
39
40
41
# File 'lib/regexpr.rb', line 34

def novalue
	self.class_eval do
		def initialize() end
		def empty?() false end
		def to_r() '' end
		def optimize() self end
	end
end

.optimize(v) ⇒ Object



19
20
21
22
23
24
# File 'lib/regexpr.rb', line 19

def optimize v
	v= v.optimize
	v= nil  if v and v.empty?
	v= v.value[ 0]  if RegExpr::Block === v and v.hidden and v.size == 1
	v
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


10
# File 'lib/regexpr.rb', line 10

def empty?() self.value.nil? end

#namesObject



11
# File 'lib/regexpr.rb', line 11

def names() @value.names.flatten.compact end

#optimizeObject



13
14
15
16
# File 'lib/regexpr.rb', line 13

def optimize
	self.value= self.class.optimize self.value
	self
end

#to_rObject



9
# File 'lib/regexpr.rb', line 9

def to_r() self.value.to_s end