module Gemmy::Patches::ArrayPatch::InstanceMethods::Arrange
Public Instance Methods
arrange()
click to toggle source
facets creates ranges from array
# File lib/gemmy/patches/array_patch.rb, line 215 def arrange array = uniq.sort_by { |e| Range === e ? e.first : e } array.inject([]) do |c, value| unless c.empty? last = c.last last_value = (Range === last ? last.last : last) current_value = (Range === value ? value.first : value) if (last_value.succ <=> current_value) == -1 c << value else first = (Range === last ? last.first : last) second = [Range === last ? last.last : last, Range === value ? value.last : value].max c[-1] = [first..second] c.flatten! end else c << value end end end
Also aliased as: rangify