class RegexForRange::Range
Attributes
first[RW]
last[RW]
Public Class Methods
new(first, last)
click to toggle source
# File lib/regex_for_range/range.rb, line 6 def initialize(first, last) @first = first @last = last end
Public Instance Methods
overlaps(range)
click to toggle source
# File lib/regex_for_range/range.rb, line 11 def overlaps(range) return self.last > range.first && range.last > self.first end
to_regex()
click to toggle source
# File lib/regex_for_range/range.rb, line 15 def to_regex result = '' first_str = self.first.to_s last_str = self.last.to_s for i in (0..first_str.length - 1) if first_str[i] == last_str[i] result += first_str[i] else result += '[' + first_str[i] + '-' + last_str[i] + ']' end end return result end