Class: Line::Matchers::Range

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/line/matchers/range.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#inspect_helper

Constructor Details

#initialize(lower, upper) ⇒ Range

Returns a new instance of Range.



10
11
12
# File 'lib/line/matchers/range.rb', line 10

def initialize(lower, upper)
  self.lower, self.upper = lower, upper
end

Instance Attribute Details

#lowerObject

Returns the value of attribute lower.



8
9
10
# File 'lib/line/matchers/range.rb', line 8

def lower
  @lower
end

#upperObject

Returns the value of attribute upper.



8
9
10
# File 'lib/line/matchers/range.rb', line 8

def upper
  @upper
end

Instance Method Details

#inspect(parent = false) ⇒ Object



25
26
27
# File 'lib/line/matchers/range.rb', line 25

def inspect(parent=false)
  inspect_helper parent, "#{lower}..#{upper}", false
end

#matches?(line, positive_index, negative_index) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
22
23
# File 'lib/line/matchers/range.rb', line 14

def matches?(line, positive_index, negative_index)
  if    negative_index && lower < 0 && upper < 0 then lower <= negative_index && negative_index <= upper
  elsif negative_index && lower < 0              then lower <= negative_index && positive_index <= upper
  elsif negative_index && upper < 0              then lower <= positive_index && negative_index <= upper
  elsif 0 < lower && 0 < upper                   then lower <= positive_index && positive_index <= upper
  elsif 0 < lower                                then lower <= positive_index
  elsif 0 < upper                                then positive_index <= upper
  else                                                false
  end
end