Sha256: a0ff7d97ce9e62fdb0cc7da325787be53570cabf1c0b09870ac68cb8963ec700

Contents?: true

Size: 406 Bytes

Versions: 1

Compression:

Stored size: 406 Bytes

Contents

require "short_number_range/version"

module ShortNumberRange
  def convert_range(options = {})
    delimiter = options[:delimiter] || ','
    short_string = options[:short_string] || '-'
    input = split(delimiter)
    input = input.map(&:to_i).sort
    input.slice_when { |prev, curr| curr != prev.next }.map{ |i| i.length > 1 ? [i.first,i.last].join(" #{short_string} ") : i.join }.join(',')
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
short_number_range-0.1.0 lib/short_number_range.rb