Sha256: 46b76317a43b97256dba1ac5f57caa7c6ea7bf5047bfc8160690377c58990978

Contents?: true

Size: 1.91 KB

Versions: 1

Compression:

Stored size: 1.91 KB

Contents

# frozen_string_literal: true

module ActiveRedisStats
  module Rank
    class Get < ActiveRedisStats::Rank::Base

      LIMIT ||= 100

      def self.all(key, with_scores: false)
        ActiveRedisDB::SortedSet
          .evaluate
          .all_reverse(primary_key(key), with_scores: with_scores) || []
      end

      def self.all_intervals(key, with_scores: false, format: :month, offset: 0)
        ikey = send("#{format}_key", offset: offset)
        all("#{key}:#{ikey}", with_scores: with_scores)
      end

      def self.between(key, with_scores: false, from:, to:)
        ActiveRedisDB::SortedSet
          .evaluate
          .between_reverse(primary_key(key), from, to, with_scores: with_scores) || []
      end

      # rubocop:disable Metrics/ParameterLists
      def self.between_intervals(key, with_scores: false, from:, to:, format: :month, offset: 0)
        ikey = send("#{format}_key", offset: offset)
        between("#{key}:#{ikey}", with_scores: with_scores, from: from, to: to)
      end
      # rubocop:enable Metrics/ParameterLists

      def self.bottom(key, with_scores: false, limit: LIMIT)
        ActiveRedisDB::SortedSet
          .evaluate
          .between(primary_key(key), 1, limit, with_scores: with_scores) || []
      end

      def self.bottom_intervals(key, with_scores: false, limit: LIMIT, format: :month, offset: 0)
        ikey = send("#{format}_key", offset: offset)
        bottom("#{key}:#{ikey}", with_scores: with_scores, limit: limit)
      end

      def self.top(key, with_scores: false, limit: LIMIT)
        ActiveRedisDB::SortedSet
          .evaluate
          .between_reverse(primary_key(key), 1, limit, with_scores: with_scores) || []
      end

      def self.top_intervals(key, with_scores: false, limit: LIMIT, format: :month, offset: 0)
        ikey = send("#{format}_key", offset: offset)
        top("#{key}:#{ikey}", with_scores: with_scores, limit: limit)
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_redis_stats-0.1.0 lib/active_redis_stats/rank/get.rb