Class: Line::Matchers::Range
- Inherits:
-
Object
- Object
- Line::Matchers::Range
- Includes:
- Helpers
- Defined in:
- lib/line/matchers/range.rb
Instance Attribute Summary collapse
-
#lower ⇒ Object
Returns the value of attribute lower.
-
#upper ⇒ Object
Returns the value of attribute upper.
Instance Method Summary collapse
-
#initialize(lower, upper) ⇒ Range
constructor
A new instance of Range.
- #inspect(parent = false) ⇒ Object
- #matches?(line, positive_index, negative_index) ⇒ Boolean
Methods included from Helpers
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
#lower ⇒ Object
Returns the value of attribute lower.
8 9 10 |
# File 'lib/line/matchers/range.rb', line 8 def lower @lower end |
#upper ⇒ Object
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
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 |