Sha256: dc74b8fe8f537542882a42cdb3af771cae6e743e787cdc0f9acb29d483cad296

Contents?: true

Size: 621 Bytes

Versions: 29

Compression:

Stored size: 621 Bytes

Contents

module Rediska
  class ZSet < Hash
    def []=(key, val)
      super(key, _floatify(val))
    end

    def increment(key, val)
      self[key] += _floatify(val)
    end

    def select_by_score(min, max)
      min = _floatify(min, true)
      max = _floatify(max, false)
      reject {|_,v| v < min || v > max }
    end

    private
    def _floatify(str, increment = true)
      if inf = str.to_s.match(/^([+-])?inf/i)
        (inf[1] == '-' ? -1.0 : 1.0) / 0.0
      elsif ((number = str.to_s.match(/^\((\d+)/i)))
         number[1].to_i + (increment ? 1 : -1)
      else
        Float(str)
      end
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
rediska-0.1.7 lib/rediska/zset.rb
rediska-0.1.6 lib/rediska/zset.rb
rediska-0.1.5 lib/rediska/zset.rb
rediska-0.1.4 lib/rediska/zset.rb
rediska-0.1.2 lib/rediska/zset.rb
rediska-0.1.1 lib/rediska/zset.rb
rediska-0.1.0 lib/rediska/zset.rb
rediska-0.0.11 lib/rediska/zset.rb
rediska-0.0.10 lib/rediska/zset.rb