Sha256: 63927d67e18f96f1beaa053010ff71abaf9394514c2371dad59c0f65f6cef1d2

Contents?: true

Size: 345 Bytes

Versions: 3

Compression:

Stored size: 345 Bytes

Contents

module Rico
  class CappedSortedMap < Map
    attr_accessor :limit

    protected

    def compute_add(items)
      unless @limit
        raise ArgumentError, "please specify a limit in item construction"
      end

      Hash[super(items).sort.pop(@limit)]
    end

    def compute_remove(items)
      Hash[super(items).sort]
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rico-0.5.0 lib/rico/capped_sorted_map.rb
rico-0.4.0 lib/rico/capped_sorted_map.rb
rico-0.3.0 lib/rico/capped_sorted_map.rb