Sha256: 63302b306e9dc38ec8fd449c0d7add0b19b2c783795902d37db1d0b9cf7c8fa2
Contents?: true
Size: 1008 Bytes
Versions: 2
Compression:
Stored size: 1008 Bytes
Contents
# -*- coding: utf-8 -*- =begin rdoc Please see README =end class Range # Parse the text to a pair of tokens and return these as a new range object. # # The separator may be two dots or three dots: # # * Two dots ".." includes the stop item. # * Three dots "..." excludes the stop item. # # This method delegates parsing of each tokens to Range.parse_helper # def self.parse(text) begin text=text.to_s if text=~/(\.\.\.?)/ start_token = $` stop_token = $' separator = $1 exclude_end = (separator == "...") return self.new(self.parse_helper(start_token), self.parse_helper(stop_token), exclude_end) end rescue end raise ArgumentError.new("#parse text must have a start token, two or three dots, and a stop token; this text does not parse: \"#{text}\"") end # Parse one item of the pair of items. # Subclasses will likely want to override this. # def self.parse_helper(text) text end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
sixarm_ruby_range_parse-1.0.2 | lib/sixarm_ruby_range_parse.rb |
sixarm_ruby_range_parse-1.0.1 | lib/sixarm_ruby_range_parse.rb |