Class: RegexPath::Segment

Inherits:
Object show all
Defined in:
lib/regex_path.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(re, captured = false, negative = false) ⇒ Segment

Returns a new instance of Segment.



14
15
16
17
18
# File 'lib/regex_path.rb', line 14

def initialize ( re, captured=false, negative=false )
  @re = Regexp.new(re)
  @captured = !!captured
  @negative = !!negative
end

Instance Attribute Details

#reObject (readonly)

Returns the value of attribute re.



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

def re
  @re
end

Instance Method Details

#==(rhs) ⇒ Object



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

def == ( rhs )
  eql?(rhs)
end

#=~(value) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/regex_path.rb', line 20

def =~ ( value )
  match_data = @re.match(value)
  if negative?
    (match_data)? nil : (//.match value)
  else
    match_data
  end
end

#captured?Boolean

Returns:

  • (Boolean)


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

def captured?
  @captured
end

#eql?(rhs) ⇒ Boolean

Returns:

  • (Boolean)


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

def eql? ( rhs )
  @re.eql?(rhs.re) and @captured.eql?(rhs.captured?)
end

#negative?Boolean

Returns:

  • (Boolean)


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

def negative?
  @negative
end