Class: GraphiteDashboardApi::Graph
- Inherits:
-
Object
- Object
- GraphiteDashboardApi::Graph
- Defined in:
- lib/graphite-dashboard-api/graph.rb
Constant Summary collapse
- PROPS =
[:from, :until, :width, :height]
Instance Method Summary collapse
-
#default_title ⇒ Object
This is probably an over simplification TODO.
- #from_hash!(hash) ⇒ Object
-
#initialize(title = nil, &block) ⇒ Graph
constructor
A new instance of Graph.
- #leading_entries ⇒ Object
- #render_options(default_options) ⇒ Object
- #target_encode ⇒ Object
- #to_hash ⇒ Object
- #url(default_options) ⇒ Object
Constructor Details
#initialize(title = nil, &block) ⇒ Graph
Returns a new instance of Graph.
20 21 22 23 24 25 |
# File 'lib/graphite-dashboard-api/graph.rb', line 20 def initialize(title = nil, &block) @title = title @targets = [] @compact_leading = false # this is tweaking stuff instance_eval(&block) if block end |
Instance Method Details
#default_title ⇒ Object
This is probably an over simplification TODO
32 33 34 |
# File 'lib/graphite-dashboard-api/graph.rb', line 32 def default_title @targets.first end |
#from_hash!(hash) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/graphite-dashboard-api/graph.rb', line 71 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 self end |
#leading_entries ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/graphite-dashboard-api/graph.rb', line 46 def leading_entries if @compact_leading leading_entries = target_encode else leading_entries = @targets end end |
#render_options(default_options) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/graphite-dashboard-api/graph.rb', line 36 def () opts = [] PROPS.each do |k| v = instance_variable_get "@#{k}".to_sym v ||= [k.to_s] opts << "#{k.to_s}=#{v}" if v end opts.join('&') end |
#target_encode ⇒ Object
54 55 56 57 58 |
# File 'lib/graphite-dashboard-api/graph.rb', line 54 def target_encode @targets.map do |target| 'target=' + target end.join('&') end |
#to_hash ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/graphite-dashboard-api/graph.rb', line 60 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 end |
#url(default_options) ⇒ Object
27 28 29 |
# File 'lib/graphite-dashboard-api/graph.rb', line 27 def url() '/render?' + () + '&' + target_encode + "&title=#{@title || default_title}" end |