Sha256: ca5861b0be9b249b5d61eba681acf0b81117e35adf8a4138ffafaae03d11336d
Contents?: true
Size: 1.03 KB
Versions: 4
Compression:
Stored size: 1.03 KB
Contents
class Usher class Splitter def self.for_delimiters(delimiters_array) delimiters = Delimiters.new(delimiters_array) delimiters_array.any?{|d| d.size > 1} ? MultiCharacterSplitterInstance.new(delimiters) : SingleCharacterSplitterInstance.new(delimiters) end class SingleCharacterSplitterInstance def initialize(delimiters) @url_split_regex = Regexp.new("[#{delimiters.collect{|d| Regexp.quote(d)}.join}]|[^#{delimiters.collect{|d| Regexp.quote(d)}.join}]+") end def split(path) path.scan(@url_split_regex) end end class MultiCharacterSplitterInstance def initialize(delimiters) @delimiters = delimiters end def split(path) split_path = path.split(delimiters_regexp) split_path.reject!{|s| s.empty? } split_path end protected def delimiters_regexp Regexp.new("(#{@delimiters.unescaped.collect{|d| Regexp.quote(d)}.join('|')})") end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
usher-0.6.6 | lib/usher/splitter.rb |
usher-0.6.5 | lib/usher/splitter.rb |
usher-0.6.4 | lib/usher/splitter.rb |
usher-0.6.3 | lib/usher/splitter.rb |