Class: Obst::Chart::DailyCount

Inherits:
Object
  • Object
show all
Defined in:
lib/obst/chart.rb

Instance Method Summary collapse

Constructor Details

#initialize(**opts) ⇒ DailyCount

Returns a new instance of DailyCount.



4
5
6
7
# File 'lib/obst/chart.rb', line 4

def initialize(**opts)
  pathspec = opts[:cfg]&.dig_any(['pathspec'], ['chart_daily_count', 'pathspec'])
  @daily_gauge = Obst::DailyGauge.new(C: opts[:C], pathspec: pathspec).lazy
end

Instance Method Details

#to_sObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/obst/chart.rb', line 9

def to_s
  labels, data = [], []
  @daily_gauge.take(28 * 3).each do |time_count|
    labels << time_count.time.strftime('%F %a')
    data << time_count.count
  end

  <<~EOF
  # Daily count

  ```chart
  type: line
  width: 98%
  legendPosition: bottom
  labels: #{labels.reverse!}
  series:
    - title: current #{data[0]}
      data: #{data.reverse!}
  ```
  EOF
end