Class: Appboard::DashboardSetup::Dashboard

Inherits:
Object
  • Object
show all
Defined in:
lib/appboard/dashboardsetup.rb

Overview

Defines dashboard

Instance Method Summary collapse

Constructor Details

#initialize(name, &block) ⇒ Dashboard

Returns a new instance of Dashboard.



6
7
8
9
10
11
12
# File 'lib/appboard/dashboardsetup.rb', line 6

def initialize(name, &block)
  @widgets = {}
  @width = 5
  @name = name
  
  instance_eval(&block)
end

Instance Method Details

#get_widgetsObject



55
56
57
58
59
60
61
62
63
# File 'lib/appboard/dashboardsetup.rb', line 55

def get_widgets
  widgets = []

  @widgets.each do |name, widget| 
    widgets << widget
  end 

  widgets
end

#has(name) ⇒ Object



65
66
67
# File 'lib/appboard/dashboardsetup.rb', line 65

def has(name)
  true if @widgets[name]
end

#nameObject



18
19
20
# File 'lib/appboard/dashboardsetup.rb', line 18

def name
  @name
end

#to_json(*a) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/appboard/dashboardsetup.rb', line 69

def to_json(*a)
  widgets = []
  
  @widgets.each do |name, widget| 
    widgets << widget
  end 
  
  {
    :name     => @name,
    :width     => @width,
    :widgets  => widgets
  }.to_json(*a)
end

#uid(value = nil) ⇒ Object



27
28
29
30
# File 'lib/appboard/dashboardsetup.rb', line 27

def uid(value = nil)
  @uid = value unless value.nil?
  @uid
end

#widget(widget_name) ⇒ Object

Define a widget. May be called inside push loop or separately

widget(‘name’)

type "..."
size "..."



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/appboard/dashboardsetup.rb', line 39

def widget(widget_name)
  if block_given?
    block = Proc.new
    widget = Widget.new(widget_name, &block)

    raise ArgumentError, "Widget with name '#{widget_name.to_s}' is already defined" if @widgets[widget_name.to_s]

    @widgets[widget_name.to_s] = widget
  else
    widget = @widgets[widget_name.to_s]

    raise ArgumentError, "Widget is not defined, to define new widget you must supply a block as the last argument" if widget.nil?
  end 	
  widget
end

#widgetsObject



14
15
16
# File 'lib/appboard/dashboardsetup.rb', line 14

def widgets
  @widgets
end

#width(value = nil) ⇒ Object



22
23
24
25
# File 'lib/appboard/dashboardsetup.rb', line 22

def width(value = nil)
  @width = value unless value.nil?
  @width
end