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 +8 -8
- data/README.md +3 -1
- data/lib/ohm/tallyable.rb +13 -7
- data/ohm-tallyable.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZDY5MTc1ZDZmZWMxOGNmYzEyODc3NzBlYTY3MGYxZjA3ODIyNmE3Mw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MzM2NDAxZWQ5Nzk1NWM2YTMxN2YzNWUwMzMxMzQzNjg2ODIxZmRhZQ==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MTdlZmI3YmQ4ZGNlMDUyNTUzOWNlOTRhZDZjOWMxMGUxMjA2ODU3NjE5ZWQ3
|
10
|
+
NDkwNTFiODE4OWJiNGJmNzViMmRkMzljY2EyNTBlYjUzZjJiOTJmNDUyN2Nj
|
11
|
+
ZmJmYjA2YzU1MjhmMTcxMjkwYjczODAzYzc3ZDRlYjc3ZTVmNTc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
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
|
data/ohm-tallyable.gemspec
CHANGED
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.
|
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-
|
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
|