Module: RegexForRange::Util
Instance Method Summary collapse
- #from_end(last) ⇒ Object
- #from_start(first) ⇒ Object
- #join(range1, range2) ⇒ Object
- #join_regex_by_or(ranges) ⇒ Object
Instance Method Details
#from_end(last) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/regex_for_range/util.rb', line 5 def from_end(last) last_str = last.to_s i = last_str.length - 1 while i >= 0 do if last_str[i] == '9' last_str[i] = '0' else last_str[i] = '0' break end i -= 1 end return Range.new(last_str.to_i, last) end |
#from_start(first) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/regex_for_range/util.rb', line 24 def from_start(first) first_str = first.to_s i = first_str.length - 1 while i >= 0 do if first_str[i] == '0' first_str[i] = '9' else first_str[i] = '9' break end i -= 1 end return Range.new(first, first_str.to_i) end |
#join(range1, range2) ⇒ Object
42 43 44 |
# File 'lib/regex_for_range/util.rb', line 42 def join(range1, range2) return Range.new(range1.first, range2.last) end |
#join_regex_by_or(ranges) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/regex_for_range/util.rb', line 46 def join_regex_by_or(ranges) results = '' ranges.each do |range| results += range.to_regex + '|' end return results[0..-2] end |