Sha256: 65b6a07d4664abfdae577703e53e2397c614eeb2d0cf937315610271e06e24a4

Contents?: true

Size: 565 Bytes

Versions: 2

Compression:

Stored size: 565 Bytes

Contents

module FakeRedis
  class ZSet < Hash

    def []=(key, val)
      super(key, _floatify(val))
    end

    # Increments the value of key by val
    def increment(key, val)
      self[key] += _floatify(val)
    end

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

    # Originally lifted from redis-rb
    def _floatify(str)
      if (( inf = str.to_s.match(/^([+-])?inf/i) ))
        (inf[1] == "-" ? -1.0 : 1.0) / 0.0
      else
        Float str
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fakeredis-0.4.3 lib/fakeredis/zset.rb
fakeredis-0.4.2 lib/fakeredis/zset.rb