Class: Obst::DailyGauge

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/obst/daily_gauge.rb

Defined Under Namespace

Classes: TimeCount

Constant Summary collapse

ONE_DAY =
60 * 60 * 24

Instance Method Summary collapse

Constructor Details

#initialize(**opts) ⇒ DailyGauge

Returns a new instance of DailyGauge.



8
9
10
# File 'lib/obst/daily_gauge.rb', line 8

def initialize(**opts)
  @path = opts[:C] || '.'
end

Instance Method Details

#each(&block) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/obst/daily_gauge.rb', line 15

def each(&block)
  return self unless block

  time = Time.parse(Time.now.strftime('%F'))
  tot = total_now
  block.call(TimeCount.new(time, tot))

  DailyIncrement.new(C: @path).each do |incr|
    time -= ONE_DAY
    tot -= incr
    block.call(TimeCount.new(time, tot))
  end
end

#total_nowObject



29
30
31
32
33
# File 'lib/obst/daily_gauge.rb', line 29

def total_now
  total = 0
  Open3.pipeline_r(['git', '-C', @path, 'ls-files'], ['wc', '-l']){ |stdout| total = stdout.read.to_i }
  total
end