Class: GraphiteDashboardApi::Graph
- Inherits:
-
Object
- Object
- GraphiteDashboardApi::Graph
show all
- Includes:
- ExtraOptions
- Defined in:
- lib/graphite-dashboard-api/graph.rb
Constant Summary
collapse
- PROPS =
[:from, :until, :width, :height]
Instance Attribute Summary
Attributes included from ExtraOptions
#extra_options
Instance Method Summary
collapse
#extra_options_from_hash!, #extra_options_to_hash, #method_missing
Constructor Details
#initialize(title = nil, &block) ⇒ Graph
Returns a new instance of Graph.
23
24
25
26
27
28
29
|
# File 'lib/graphite-dashboard-api/graph.rb', line 23
def initialize(title = nil, &block)
@title = title
@targets = []
@compact_leading = false @extra_options = {}
instance_eval(&block) if block
end
|
Instance Method Details
#default_title ⇒ Object
This is probably an over simplification TODO
36
37
38
|
# File 'lib/graphite-dashboard-api/graph.rb', line 36
def default_title
@targets.first
end
|
#from_hash!(hash) ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/graphite-dashboard-api/graph.rb', line 76
def from_hash!(hash)
@title = hash['title']
PROPS.each do |k|
value = hash[k.to_s]
instance_variable_set("@#{k}".to_sym, value) if value
end
if hash['target']
hash['target'].each do |target|
@targets << target
end
end
std_options = ['title', 'target', PROPS].map { |k| k.to_s }
(std_options, hash)
self
end
|
#leading_entries ⇒ Object
50
51
52
53
54
55
56
|
# File 'lib/graphite-dashboard-api/graph.rb', line 50
def leading_entries
if @compact_leading
leading_entries = target_encode
else
leading_entries = @targets
end
end
|
#render_options(default_options) ⇒ Object
40
41
42
43
44
45
46
47
48
|
# File 'lib/graphite-dashboard-api/graph.rb', line 40
def render_options(default_options)
opts = []
PROPS.each do |k|
v = instance_variable_get "@#{k}".to_sym
v ||= default_options[k.to_s]
opts << "#{k.to_s}=#{v}" if v
end
opts.join('&')
end
|
#target_encode ⇒ Object
58
59
60
61
62
|
# File 'lib/graphite-dashboard-api/graph.rb', line 58
def target_encode
@targets.map do |target|
'target=' + target
end.join('&')
end
|
#to_hash ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/graphite-dashboard-api/graph.rb', line 64
def to_hash
hash = {}
hash['title'] = @title if @title
PROPS.each do |k|
v = instance_variable_get "@#{k}".to_sym
hash[k.to_s] = v if v
end
hash['target'] = @targets
hash.merge!()
hash
end
|
#url(default_options) ⇒ Object
31
32
33
|
# File 'lib/graphite-dashboard-api/graph.rb', line 31
def url(default_options)
'/render?' + render_options(default_options) + '&' + target_encode + "&title=#{@title || default_title}"
end
|