class Rediska::SortedSetArgumentHandler

Attributes

aggregate[R]
keys[RW]
number_of_keys[RW]
type[RW]
weights[RW]

Public Class Methods

new(args) click to toggle source
# File lib/rediska/sorted_set_argument_handler.rb, line 6
def initialize(args)
  @number_of_keys = args.shift
  @keys = args.shift(number_of_keys)
  args.inject(self) {|handler, item| handler.handle(item) }

  # Defaults.
  @weights ||= Array.new(number_of_keys) { 1 }
  @aggregate ||= :sum

  # Validation.
  raise Redis::CommandError, 'ERR syntax error' unless weights.size == number_of_keys
  raise Redis::CommandError, 'ERR syntax error' unless [:min, :max, :sum].include?(aggregate)
end

Public Instance Methods

aggregate=(str) click to toggle source
# File lib/rediska/sorted_set_argument_handler.rb, line 20
def aggregate=(str)
  raise Redis::CommandError, 'ERR syntax error' if @aggregate

  @aggregate = str.to_s.downcase.to_sym
end
handle(item) click to toggle source
# File lib/rediska/sorted_set_argument_handler.rb, line 26
def handle(item)
  case item
  when 'WEIGHTS'
    @type = :weights
    @weights = []
  when 'AGGREGATE'
    @type = :aggregate
  when nil
    raise Redis::CommandError, 'ERR syntax error'
  else
    send "handle_#{type}", item
  end

  self
end
handle_aggregate(item) click to toggle source
# File lib/rediska/sorted_set_argument_handler.rb, line 46
def handle_aggregate(item)
  @aggregate = item
end
handle_weights(item) click to toggle source
# File lib/rediska/sorted_set_argument_handler.rb, line 42
def handle_weights(item)
  @weights << item
end
inject_block() click to toggle source
# File lib/rediska/sorted_set_argument_handler.rb, line 50
def inject_block
  lambda { |handler, item| handler.handle(item) }
end