leftronic 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,14 +1,24 @@
1
+ Leftronic
2
+ =========
1
3
  A simple interface for the Leftronics dashboard
4
+
2
5
  Leftronics is a dashboard-as-a-service. It supports five custom data update types:
3
6
 
4
- leaderboard(name, entries)
5
- list(name, entries)
6
- map(name, latitude, longitude)
7
- number(name, number)
8
- text(name, title, text)
7
+ * leaderboard(name, entries)
8
+ * list(name, entries)
9
+ * map(name, latitude, longitude)
10
+ * number(name, number)
11
+ * text(name, title, text)
12
+
13
+ Installation
14
+ ============
15
+
16
+ gem install leftronic
9
17
 
10
- Example usage:
18
+ Example Usage
19
+ =============
11
20
 
21
+ require 'rubygems' # Not necessary in ruby 1.9.2
12
22
  require 'leftronic'
13
23
  dashboard = Leftronic.new("my-leftronic-api-key")
14
24
  dashboard.leaderboard("top_deployed", [{"engine" => 200}, {"mockr" => 15}, {"fatfreecrm" => 59}])
@@ -17,6 +27,13 @@ Example usage:
17
27
  dashboard.number("app_count", 5000)
18
28
  dashboard.text("MongoDB Server up")
19
29
 
20
- License:
21
30
 
31
+ TODO
32
+ ====
33
+
34
+ * Accept a block for Leftronic#leaderboard and Leftronic#list to have better control over how the top 12 get picked
35
+ * Change Leftronic#leaderboard entries format from [{:a => "0"}, {:b => "1"}] to {:a => "0", :b => "1"}
36
+
37
+ LICENSE
38
+ =======
22
39
  MIT
data/lib/leftronic.rb CHANGED
@@ -39,24 +39,33 @@ class Leftronic
39
39
 
40
40
  # Push a new leaderboard
41
41
  # Entries is a hash of the form {:key_name_1 => :value, :key_name_2 => :value}
42
+ # Sorts by value, and then pushes the top 12
42
43
  def leaderboard(name, entries)
43
44
  values = []
44
45
 
45
46
  entries.each do |hash|
46
47
  hash.each_pair do |key, value|
47
- values << {"name" => key, "value" => value}
48
+ values << {"name" => key.to_s, "value" => value}
48
49
  end
49
50
  end
50
51
 
51
- puts ({"leaderboard" => values}.inspect)
52
+ values = values.sort do |a, b|
53
+ if b.nil?
54
+ a
55
+ else
56
+ a["value"] <=> b["value"]
57
+ end
58
+ end[0..11]
59
+
52
60
  push(name, {"leaderboard" => values})
53
61
  end
54
62
 
55
63
 
56
64
  # Push a list
57
65
  # Entries is simply an array
66
+ # Only pushes the first 12 items of the list
58
67
  def list(name, entries)
59
- values = entries.collect do |item|
68
+ values = entries[0..11].collect do |item|
60
69
  {"listItem" => item}
61
70
  end
62
71
 
@@ -1,3 +1,3 @@
1
1
  module Leftronic
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: leftronic
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Sean Grove
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-08 00:00:00 -07:00
13
+ date: 2011-06-09 00:00:00 -07:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -47,7 +47,7 @@ extra_rdoc_files: []
47
47
  files:
48
48
  - .gitignore
49
49
  - Gemfile
50
- - README
50
+ - README.md
51
51
  - Rakefile
52
52
  - leftronic.gemspec
53
53
  - lib/leftronic.rb