Sha256: fcc6ec1a3fc7219fd570e7b0a30aa0e1f2f11d361717b9a2dd0e0e875244b304

Contents?: true

Size: 536 Bytes

Versions: 5

Compression:

Stored size: 536 Bytes

Contents

module Lunar
  class ResultSet
    include Enumerable

    attr :sorted_set_key

    def initialize(sorted_set_key, &block)
      @sorted_set_key = sorted_set_key
      @block          = block
    end

    def each(&block)
      all.each(&block)
    end

    def all(options = {})
      start  = Integer(options[:start] || 0)
      finish = start + Integer(options[:limit] || 0) - 1

      Lunar.redis.zrevrange(sorted_set_key, start, finish).map(&@block)
    end

    def size
      Lunar.redis.zcard(sorted_set_key)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
lunar-0.2.3 lib/lunar/result_set.rb
lunar-0.2.2 lib/lunar/result_set.rb
lunar-0.2.1 lib/lunar/result_set.rb
lunar-0.2.0 lib/lunar/result_set.rb
lunar-0.1.1 lib/lunar/result_set.rb