Class: Rstatsd::Chart

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/rstatsd/chart.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#counter_key_name, #fetch_counters, #format_key, #redis, #redis_data_for, #timer_key_name

Constructor Details

#initialize(query_string) ⇒ Chart

Returns a new instance of Chart.



10
11
12
13
# File 'lib/rstatsd/chart.rb', line 10

def initialize(query_string)
  @query_string = query_string
  @data = {}
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



8
9
10
# File 'lib/rstatsd/chart.rb', line 8

def data
  @data
end

Instance Method Details

#column_typesObject



22
23
24
25
26
27
# File 'lib/rstatsd/chart.rb', line 22

def column_types
  targets.inject([['datetime', 'Timestamp']]) do |memo, target|
    memo << ['number', target.capitalize]
    memo
  end
end

#draw_chart {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



39
40
41
42
# File 'lib/rstatsd/chart.rb', line 39

def draw_chart
  @data = JSON.dump(fetch_counters(targets))
  yield self
end

#heightObject



48
49
50
# File 'lib/rstatsd/chart.rb', line 48

def height
  480
end

#targetsObject



15
16
17
18
19
20
# File 'lib/rstatsd/chart.rb', line 15

def targets
  @query_string.split("&").map do |term|
    param_name, value = term.split("=")
    value if param_name == 'target'
  end
end

#titleObject



29
30
31
32
33
34
35
36
37
# File 'lib/rstatsd/chart.rb', line 29

def title
  @query_string.split("&").detect do |term|
    param_name, value = term.split("=")
    if param_name == 'title'
      return URI.unescape(value)
    end
  end
  targets.map(&:capitalize).join(', ')
end

#widthObject



44
45
46
# File 'lib/rstatsd/chart.rb', line 44

def width
  800
end