Sha256: 2e7601fa98c1678f6a13dc632622603fc06c512c3b2688989b9025289959eeee

Contents?: true

Size: 540 Bytes

Versions: 1

Compression:

Stored size: 540 Bytes

Contents

module Linner
  module Sort

    def sort(before: [], after: [])
      sort_by_before(self, before)
      sort_by_after(self, after)
      self
    end

    private
    def sort_by_before(list, before)
      before.reverse.each do |f|
        if i = list.index {|x| x =~ /#{f}/i}
          list.unshift list.delete_at i
        end
      end
    end

    def sort_by_after(list, after)
      after.reverse.each do |f|
        if i = list.index {|x| x =~ /#{f}/i}
          list.push list.delete_at i
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
linner-0.1.0 lib/linner/sort.rb