Class: Anchoring

Inherits:
Object show all
Includes:
Comparable
Defined in:
app/models/regexp_sequence.rb

Overview

class RegexpTree < NestedArray # declare class end #RegexpTree reopen later Postfix operators and brackets end embeddded arrays

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(regexp_tree) ⇒ Anchoring

Returns a new instance of Anchoring.


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/models/regexp_sequence.rb', line 16

def initialize(regexp_tree)
	@start_base=0
	@end_base=-1
	self[:start_anchor]=if regexp_tree[0]=='^' then
		@start_base=1
		'^'
	else
		nil
	end #if
	self[:end_anchor]=if regexp_tree[-1]=='$' then
		@end_base=-2
		'$'
	else
		nil
	end #if
	self[:base_regexp]=regexp_tree[@start_base..@end_base]
end

Instance Attribute Details

#end_baseObject (readonly)

Returns the value of attribute end_base


15
16
17
# File 'app/models/regexp_sequence.rb', line 15

def end_base
  @end_base
end

#start_baseObject (readonly)

Returns the value of attribute start_base


15
16
17
# File 'app/models/regexp_sequence.rb', line 15

def start_base
  @start_base
end

Instance Method Details

#<=>(other) ⇒ Object

compare_anchor


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/models/regexp_sequence.rb', line 44

def <=>(other)
	comparison_case=[compare_anchor(other, :start_anchor), compare_anchor(other, :end_anchor)]
	case comparison_case
	when [0,0]
		return 0
	when [0,1], [1,1], [1,0] #specialized and equal
		return 1
	when [0,-1], [-1,-1] #specialized and equal
		return -1
	when [-1,1], [1,-1] #disagreement
		nil
	else
		raise "In Anchoring.<=> Unexpected case=#{comparison_case.inspect},self=#{self.inspect}, other=#{other.inspect}"
	end #case
end

#compare_anchor(other, key) ⇒ Object

initialize


33
34
35
36
37
38
39
40
41
42
43
# File 'app/models/regexp_sequence.rb', line 33

def compare_anchor(other, key)
	if self[key]==other[key] then
		return 0
	elsif other[key] then 
		return 1
	elsif self[key] then 
		return -1
	else
		return nil
	end #if
end