redis-bid 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/redis_bid.rb +7 -6
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b3dc1a94a8e12bc67bbec949edd5cd604126b3b5
4
- data.tar.gz: a955e6cee9d98855e47c28d3eaba476920ca1fc3
3
+ metadata.gz: 76d99d63cab6355633ad31a5227be635543a8f08
4
+ data.tar.gz: 7ef3bf93cb3dd2f60bc7f48cb21f2ed3d545f833
5
5
  SHA512:
6
- metadata.gz: fbbcf8318bf5a7a2fab691a613767940176be613c7765dc3d01906f9b579e4f6f0094df9f91c7a45c443175f7682eec42762ba6a8dd205f4f275cb9abc193786
7
- data.tar.gz: 43b78e951bd5da6f772e819b842fadbcf34e6d086908fc1cf330079c16f58d990c99d1259429911770842c1c285f2ccf7915677e019ef6c53215570eadabf0d2
6
+ metadata.gz: 5200e8fb0a4d21d5353299d8ef0912121134a0926693778dfbe03a448f41cb6481681063e7033a1ea2c079f4c4fbf5f6fd188ddfb39e2133ff0f17f3dc7dc071
7
+ data.tar.gz: f956881154283c19bec703a36177609423b6f47860e9006b54b94f4f88ac78ddfbd252196381d05c26edcc9395f95aa7f0ffbd0b9abe4a3c1e8dadb9c683984d
data/lib/redis_bid.rb CHANGED
@@ -3,7 +3,7 @@ require 'redis'
3
3
  class RedisBid
4
4
 
5
5
  DEFAULT_USER_ID = 0
6
- MIN_BID_SCORE = 0
6
+ DEFAULT_MIN_BID_SCORE = 0
7
7
 
8
8
  BID_ITEMS_KEY_PREFIX = "bid_items"
9
9
  BID_ITEM_KEY_PREFIX = "bid"
@@ -14,7 +14,7 @@ class RedisBid
14
14
  end
15
15
 
16
16
  def self.register_bid_item(bid_id, options = {})
17
- options = { min_score: MIN_BID_SCORE }.merge(options)
17
+ options = { min_bid_score: DEFAULT_MIN_BID_SCORE }.merge(options)
18
18
  redis.sadd(BID_ITEMS_KEY_PREFIX, bid_id)
19
19
  set_min_bid(bid_id, options[:min_bid_score])
20
20
  end
@@ -24,6 +24,7 @@ class RedisBid
24
24
  end
25
25
 
26
26
  def self.set_min_bid(bid_id, score)
27
+ return false if score < DEFAULT_MIN_BID_SCORE
27
28
  return false unless is_registered?(bid_id)
28
29
  redis.hset("min_bid", bid_id, score)
29
30
  true
@@ -38,7 +39,7 @@ class RedisBid
38
39
  end
39
40
 
40
41
  def self.add_user_bid(user_id, bid_id, score)
41
- return false if score < MIN_BID_SCORE
42
+ return false if score < get_min_bid(bid_id)
42
43
  return false unless is_registered?(bid_id)
43
44
  redis.zadd("BID_ITEM_KEY_PREFIX:#{bid_id}", score, user_id)
44
45
  true
@@ -53,14 +54,14 @@ class RedisBid
53
54
  end
54
55
 
55
56
  def self.list_user_bids(bid_id, options = {})
56
- options = { min_score: MIN_BID_SCORE, max_score: "+inf", with_scores: false, order: "desc"}.merge(options)
57
+ options = { min_bid_score: DEFAULT_MIN_BID_SCORE, max_score: "+inf", with_scores: false, order: "desc"}.merge(options)
57
58
  return list_user_bids_in_descending_order(bid_id, options) if options[:order] == "desc"
58
- redis.zrangebyscore("BID_ITEM_KEY_PREFIX:#{bid_id}", options[:min_score], options[:max_score], with_scores: options[:with_scores])
59
+ redis.zrangebyscore("BID_ITEM_KEY_PREFIX:#{bid_id}", options[:min_bid_score], options[:max_score], with_scores: options[:with_scores])
59
60
  end
60
61
 
61
62
  private
62
63
 
63
64
  def self.list_user_bids_in_descending_order(bid_id, options = {})
64
- redis.zrevrangebyscore("BID_ITEM_KEY_PREFIX:#{bid_id}", options[:max_score], options[:min_score], with_scores: options[:with_scores])
65
+ redis.zrevrangebyscore("BID_ITEM_KEY_PREFIX:#{bid_id}", options[:max_score], options[:min_bid_score], with_scores: options[:with_scores])
65
66
  end
66
67
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-bid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - tkang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-29 00:00:00.000000000 Z
11
+ date: 2014-02-12 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Bid System
14
14
  email: tkang1@gmail.com