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

Parameters:

  • string (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

Parameters:

  • values (String)
  • max (Hash)

    Hash with text and value keys

  • min (Hash)

    Hash with text and value keys

Returns:

  • (String)

    the geck-o-meter chart as json string



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

Parameters:

  • values (Array) (defaults to: [])
  • axisx (Array) (defaults to: [])
  • axisy (Array) (defaults to: [])
  • colour (String) (defaults to: "#ff9900")

Returns:

  • (String)

    the line chart as json string



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

Parameters:

  • number1 (Hash)
  • number2 (Hash) (defaults to: nil)

Returns:

  • (String)

    the number widget as jons string



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

Parameters:

  • values (Array) (defaults to: [])

    array of hash with: value, label and optional colour keys

Returns:

  • (String)

    the pie chart as json string



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

Parameters:

  • red (Hash)
  • amber (Hash)
  • green (Hash)

Returns:

  • (String)

    the rag widget as json string



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

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