sinatra-geckoboard 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +27 -3
  2. data/lib/sinatra/geckoboard.rb +26 -2
  3. metadata +14 -14
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  # Sinatra Geckoboard
2
2
 
3
- **Work in progress**
4
-
5
3
  A little [Sinatra](http://www.sinatrarb.com/) extension to expose data nicely to [Geckoboard](http://www.geckoboard.com/).
6
4
 
5
+ We are using it in production.
6
+
7
7
  ## Install
8
8
 
9
9
  Install with Rubygems:
@@ -39,7 +39,31 @@ class App < Sinatra::Base
39
39
  end
40
40
  ```
41
41
 
42
- ## Licence
42
+ ### Pie Chart
43
+
44
+ Render a pie chart widget. You should pass an array of `Hash`. If the key `colour` is ommited, a colour will be generated with the `label` key.
45
+
46
+ ```ruby
47
+ pie_chart(values)
48
+ ```
49
+
50
+ ### Line Chart
51
+
52
+ Render a line_chart widget.
53
+
54
+ ```ruby
55
+ line_chart(values, axisx, axisy, colour)
56
+ ```
57
+
58
+ ### Geck-O-Meter
59
+
60
+ Render a Geck-O-Meter widget.
61
+
62
+ ```ruby
63
+ geck_o_meter(number, max, min)
64
+ ```
65
+
66
+ ## License
43
67
 
44
68
  MIT License
45
69
 
@@ -1,9 +1,17 @@
1
+ require 'digest/md5'
1
2
  require 'json'
2
3
 
3
4
  module Sinatra
4
5
  module Geckoboard
5
6
 
6
7
  module Helpers
8
+ # Create a color from string
9
+ #
10
+ # @param [String] string
11
+ def create_color(string)
12
+ "##{Digest::MD5.hexdigest(string)[0..5]}"
13
+ end
14
+
7
15
  # Render a line chart widget
8
16
  # Set content type as json
9
17
  # http://support.geckoboard.com/entries/274940-custom-chart-widget-type-definitions
@@ -13,7 +21,7 @@ module Sinatra
13
21
  # @param [Array] axisy
14
22
  # @param [String] colour
15
23
  # @return [String] the line chart as json string
16
- def line_chart(values=[], axisx=[], axisy=[], colour="")
24
+ def line_chart(values=[], axisx=[], axisy=[], colour="#ff9900")
17
25
  render_widget "item" => values,
18
26
  "settings" => {
19
27
  "axisx" => axisx,
@@ -26,12 +34,28 @@ module Sinatra
26
34
  # Set content type as json
27
35
  # http://support.geckoboard.com/entries/274940-custom-chart-widget-type-definitions
28
36
  #
29
- # @param [Array] values array of hash with: value, label and colour keys
37
+ # @param [Array] values array of hash with: value, label and optional colour keys
30
38
  # @return [String] the pie chart as json string
31
39
  def pie_chart(values=[])
40
+ values.map! do |value|
41
+ value['colour'] ||= create_color value['label']
42
+ value
43
+ end
32
44
  render_widget "item" => values
33
45
  end
34
46
 
47
+ # Render a geck-o-meter widget
48
+ # Set content type as json
49
+ # http://support.geckoboard.com/entries/274940-custom-chart-widget-type-definitions
50
+ #
51
+ # @param [String] values
52
+ # @param [Hash] max Hash with text and value keys
53
+ # @param [Hash] min Hash with text and value keys
54
+ # @return [String] the geck-o-meter chart as json string
55
+ def geck_o_meter(value, max, min)
56
+ render_widget "item" => value, "max" => max, "min" => min
57
+ end
58
+
35
59
  protected
36
60
  def render_widget(widget)
37
61
  content_type :json
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-geckoboard
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-11 00:00:00.000000000Z
12
+ date: 2011-10-24 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
16
- requirement: &17976980 !ruby/object:Gem::Requirement
16
+ requirement: &18868100 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '1.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *17976980
24
+ version_requirements: *18868100
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: json
27
- requirement: &17976500 !ruby/object:Gem::Requirement
27
+ requirement: &18904260 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '1.0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *17976500
35
+ version_requirements: *18904260
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: bundler
38
- requirement: &17976120 !ruby/object:Gem::Requirement
38
+ requirement: &18903880 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *17976120
46
+ version_requirements: *18903880
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: minitest
49
- requirement: &17975580 !ruby/object:Gem::Requirement
49
+ requirement: &18903340 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '2.0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *17975580
57
+ version_requirements: *18903340
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rake
60
- requirement: &17975160 !ruby/object:Gem::Requirement
60
+ requirement: &18902920 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *17975160
68
+ version_requirements: *18902920
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rack-test
71
- requirement: &17974700 !ruby/object:Gem::Requirement
71
+ requirement: &18902460 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *17974700
79
+ version_requirements: *18902460
80
80
  description: A little Sinatra extension to expose data nicely to Geckoboard.
81
81
  email: francois.de.metz@af83.com
82
82
  executables: []