Class: Rediska::SortedSetArgumentHandler
- Inherits:
-
Object
- Object
- Rediska::SortedSetArgumentHandler
- Defined in:
- lib/rediska/sorted_set_argument_handler.rb
Instance Attribute Summary collapse
-
#aggregate ⇒ Object
Returns the value of attribute aggregate.
-
#keys ⇒ Object
Returns the value of attribute keys.
-
#number_of_keys ⇒ Object
Returns the value of attribute number_of_keys.
-
#type ⇒ Object
Returns the value of attribute type.
-
#weights ⇒ Object
Returns the value of attribute weights.
Instance Method Summary collapse
- #handle(item) ⇒ Object
- #handle_aggregate(item) ⇒ Object
- #handle_weights(item) ⇒ Object
-
#initialize(args) ⇒ SortedSetArgumentHandler
constructor
A new instance of SortedSetArgumentHandler.
- #inject_block ⇒ Object
Constructor Details
#initialize(args) ⇒ SortedSetArgumentHandler
Returns a new instance of SortedSetArgumentHandler.
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# 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 |
Instance Attribute Details
#aggregate ⇒ Object
Returns the value of attribute aggregate.
3 4 5 |
# File 'lib/rediska/sorted_set_argument_handler.rb', line 3 def aggregate @aggregate end |
#keys ⇒ Object
Returns the value of attribute keys.
4 5 6 |
# File 'lib/rediska/sorted_set_argument_handler.rb', line 4 def keys @keys end |
#number_of_keys ⇒ Object
Returns the value of attribute number_of_keys.
4 5 6 |
# File 'lib/rediska/sorted_set_argument_handler.rb', line 4 def number_of_keys @number_of_keys end |
#type ⇒ Object
Returns the value of attribute type.
4 5 6 |
# File 'lib/rediska/sorted_set_argument_handler.rb', line 4 def type @type end |
#weights ⇒ Object
Returns the value of attribute weights.
4 5 6 |
# File 'lib/rediska/sorted_set_argument_handler.rb', line 4 def weights @weights end |
Instance Method Details
#handle(item) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# 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) ⇒ Object
46 47 48 |
# File 'lib/rediska/sorted_set_argument_handler.rb', line 46 def handle_aggregate(item) @aggregate = item end |
#handle_weights(item) ⇒ Object
42 43 44 |
# File 'lib/rediska/sorted_set_argument_handler.rb', line 42 def handle_weights(item) @weights << item end |
#inject_block ⇒ Object
50 51 52 |
# File 'lib/rediska/sorted_set_argument_handler.rb', line 50 def inject_block lambda { |handler, item| handler.handle(item) } end |