ohm-tallyable 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MWRmOGJiMzVmNzQxODAyNDU1YTUyYzMzMDAyN2VjNjg3ZmIwYjBhYw==
4
+ ZDY5MTc1ZDZmZWMxOGNmYzEyODc3NzBlYTY3MGYxZjA3ODIyNmE3Mw==
5
5
  data.tar.gz: !binary |-
6
- YWFjYTE0ZDRiMjRhMDg2YjIyMjQ5MTRiOWZiM2YxZWM4NTFjNjQxMw==
6
+ MzM2NDAxZWQ5Nzk1NWM2YTMxN2YzNWUwMzMxMzQzNjg2ODIxZmRhZQ==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- NzJkODc2YjFiNDkyYjIxMGI4ZTMzNzBmOTY5YzBmNmY2NGZmMzdiOWE5OWFh
10
- YTI0ZjUyYTIwZTNhYzAxNmYzMGM4NWIxY2NhOGIxY2Y5ZWViODE4NjI1NGU5
11
- MmMwZDhiOWMyZTliMmIwNThjMGQ5MmM4MDM2MTE2ZDAwZTE1NDA=
9
+ MTdlZmI3YmQ4ZGNlMDUyNTUzOWNlOTRhZDZjOWMxMGUxMjA2ODU3NjE5ZWQ3
10
+ NDkwNTFiODE4OWJiNGJmNzViMmRkMzljY2EyNTBlYjUzZjJiOTJmNDUyN2Nj
11
+ ZmJmYjA2YzU1MjhmMTcxMjkwYjczODAzYzc3ZDRlYjc3ZTVmNTc=
12
12
  data.tar.gz: !binary |-
13
- OTkwNDQyM2JiYjM0NGY5MjAxZDNmNzY0NWE3ODEyOWY4Y2I4MTIzNGE3OWNi
14
- YWEwNDYxMGIyOGNiMWRjZDYxNjE4N2NmOTg3YjJlNmFhZDVjYmRjMzUyMTI5
15
- MGU5MmQwZmI5YzlmNDlhOGM5NTRmMjY3NzBlZTQ5MmUxYzFmZjU=
13
+ NWU2YjZhZTNhNWFkODE2MjM0NTVlMDFlMDFhMGZiYjA3ZTUyYzQxYzI5MDY5
14
+ Y2QzZTlhNjIzM2U4YmRhYjg3ODJiN2IwNjMyNGY4YzM5Y2FkZGIxNThmMTgy
15
+ MzVjNTdjNzQxMmYzNzZiOTZiODVmOTQ4NzZlMTEyYTQ1Mjc3Mjc=
data/README.md CHANGED
@@ -1,7 +1,9 @@
1
-
2
1
  ohm-tallyable
3
2
  =============
4
3
 
4
+ [![Gem Version](https://badge.fury.io/rb/ohm-tallyable.png)](http://badge.fury.io/rb/ohm-tallyable)
5
+ [![Code Climate](https://codeclimate.com/github/educabilia/ohm-tallyable.png)](https://codeclimate.com/github/educabilia/ohm-tallyable)
6
+
5
7
  A tally plugin for Ohm
6
8
 
7
9
 
data/lib/ohm/tallyable.rb CHANGED
@@ -13,18 +13,24 @@ module Ohm
13
13
  end
14
14
 
15
15
  def leaderboard(attribute, by=nil)
16
+ raise ArgumentError if !_has_tally(attribute, by)
17
+
18
+ _load_zset(_tally_key(attribute, by))
19
+ .map { |k, v| [k, v.to_i] }
20
+ .sort_by { |k, v| [-v, k] }
21
+ end
22
+
23
+ def _has_tally(attribute, by=nil)
16
24
  tally = tallies[attribute]
17
- if tally.nil? || (tally[:by] && (by.nil? || !by.include?(tally[:by])))
18
- raise ArgumentError
19
- end
25
+ !!(tally && (!tally[:by] || (by && by.include?(tally[:by]))))
26
+ end
27
+
28
+ def _tally_key(attribute, by=nil)
20
29
  key = self.key[:tallies][attribute]
21
30
  if by
22
31
  key = key[by.keys.first][by.values.first]
23
32
  end
24
-
25
- _load_zset(key)
26
- .map { |k, v| [k, v.to_i] }
27
- .sort_by { |k, v| [-v, k] }
33
+ key
28
34
  end
29
35
 
30
36
  if Redis::VERSION.to_i == 2
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'ohm-tallyable'
3
- s.version = '0.1.1'
3
+ s.version = '0.1.2'
4
4
  s.summary = "Ohm Tally Plugin"
5
5
  s.description = "A tally plugin for Ohm that keeps counts of records for every value of an attribute"
6
6
  s.author = "Federico Bond"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ohm-tallyable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Federico Bond
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-07 00:00:00.000000000 Z
11
+ date: 2013-08-13 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A tally plugin for Ohm that keeps counts of records for every value of
14
14
  an attribute