Class: FnordMetric::Dashboard

Inherits:
Object
  • Object
show all
Defined in:
lib/fnordmetric/dashboard.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Dashboard

Returns a new instance of Dashboard.



5
6
7
8
9
# File 'lib/fnordmetric/dashboard.rb', line 5

def initialize(options={})    
  raise "please provide a :title" unless options[:title]        
  @widgets = Array.new
  @options = options
end

Instance Attribute Details

#widgetsObject

Returns the value of attribute widgets.



3
4
5
# File 'lib/fnordmetric/dashboard.rb', line 3

def widgets
  @widgets
end

Instance Method Details

#add_widget(w) ⇒ Object



11
12
13
# File 'lib/fnordmetric/dashboard.rb', line 11

def add_widget(w)
  @widgets << w
end

#titleObject



15
16
17
# File 'lib/fnordmetric/dashboard.rb', line 15

def title
  @options[:title]
end

#to_jsonObject



23
24
25
26
27
28
29
30
31
32
# File 'lib/fnordmetric/dashboard.rb', line 23

def to_json
  {
    :title => title,
    :widgets => {}.tap { |wids|
      @widgets.each do |w|
        wids[w.token] = w.render
      end
    }
  }.to_json
end

#tokenObject



19
20
21
# File 'lib/fnordmetric/dashboard.rb', line 19

def token
  title.to_s.gsub(/[\W]/, '')
end