Class: FnordMetric::Dashboard

Inherits:
Object
  • Object
show all
Defined in:
lib/fnordmetric/web/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/web/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/web/dashboard.rb', line 3

def widgets
  @widgets
end

Instance Method Details

#add_widget(w) ⇒ Object



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

def add_widget(w)
  @widgets << w
end

#groupObject



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

def group
  @options[:group] || "Dashboards"
end

#titleObject



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

def title
  @options[:title]
end

#to_jsonObject



29
30
31
32
33
34
35
36
37
38
# File 'lib/fnordmetric/web/dashboard.rb', line 29

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

#tokenObject



23
24
25
26
27
# File 'lib/fnordmetric/web/dashboard.rb', line 23

def token
  token = title.to_s.gsub(/[\W]/, '')
  token = Digest::SHA1.hexdigest(title.to_s) if token.empty?
  token
end