Module: Sinatra::Geckoboard::Helpers

Defined in:
lib/sinatra/geckoboard.rb

Instance Method Summary collapse

Instance Method Details

#create_color(string) ⇒ Object

Create a color from string



11
12
13
# File 'lib/sinatra/geckoboard.rb', line 11

def create_color(string)
  "##{Digest::MD5.hexdigest(string)[0..5]}"
end

#geck_o_meter(value, max, min) ⇒ String

Render a geck-o-meter widget Set content type as json support.geckoboard.com/entries/274940-custom-chart-widget-type-definitions



55
56
57
# File 'lib/sinatra/geckoboard.rb', line 55

def geck_o_meter(value, max, min)
  render_widget "item" => value, "max" => max, "min" => min
end

#line_chart(values = [], axisx = [], axisy = [], colour = "#ff9900") ⇒ String

Render a line chart widget Set content type as json support.geckoboard.com/entries/274940-custom-chart-widget-type-definitions



24
25
26
27
28
29
30
31
# File 'lib/sinatra/geckoboard.rb', line 24

def line_chart(values=[], axisx=[], axisy=[], colour="#ff9900")
  render_widget "item" => values,
                "settings" => {
                   "axisx" => axisx,
                   "axisy" => axisy,
                   "colour" => colour
                }
end

#number(number1, number2 = nil) ⇒ String

Render a number widget Set content type as json support.geckoboard.com/entries/231507-custom-widget-type-definitions



78
79
80
81
82
# File 'lib/sinatra/geckoboard.rb', line 78

def number(number1, number2=nil)
  values = [number1]
  values << number2 unless number2.nil?
  render_widget "item" => values
end

#pie_chart(values = []) ⇒ String

Render a pie chart widget Set content type as json support.geckoboard.com/entries/274940-custom-chart-widget-type-definitions



39
40
41
42
43
44
45
# File 'lib/sinatra/geckoboard.rb', line 39

def pie_chart(values=[])
  values.map! do |value|
    value['colour'] ||= create_color value['label']
    value
  end
  render_widget "item" => values
end

#rag(red, amber, green) ⇒ String

Render a RAG widget Set content type as json support.geckoboard.com/entries/231507-custom-widget-type-definitions



67
68
69
# File 'lib/sinatra/geckoboard.rb', line 67

def rag(red, amber, green)
  render_widget "item" => [red, amber, green]
end