Class: TokiCLI::Helpers

Inherits:
Object
  • Object
show all
Defined in:
lib/API/helpers.rb

Instance Method Summary collapse

Instance Method Details

#calc_apps_total(data) ⇒ Object



38
39
40
41
42
# File 'lib/API/helpers.rb', line 38

def calc_apps_total(data)
  total = 0
  data.each { |obj| total += obj['total']['seconds'] }
  return total
end

#calc_logs_total(data) ⇒ Object



44
45
46
47
48
# File 'lib/API/helpers.rb', line 44

def calc_logs_total(data)
  total = 0
  data.each { |k, v| total += v['duration']['seconds'] }
  return total
end

#check_date_validity(day) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/API/helpers.rb', line 22

def check_date_validity(day)
  begin
    DateTime.strptime(day, '%Y-%m-%d')
  rescue ArgumentError, TypeError => e
    false
  end
end

#epoch_to_date(epoch) ⇒ Object



18
19
20
# File 'lib/API/helpers.rb', line 18

def epoch_to_date(epoch)
  Time.at(epoch).to_time
end

#readable_time(obj) ⇒ Object



30
31
32
# File 'lib/API/helpers.rb', line 30

def readable_time(obj)
  "#{obj['hours']}h #{'%.2d' % obj['minutes']}m #{'%.2d' % obj['seconds']}s"
end

#readable_time_log(obj) ⇒ Object



34
35
36
# File 'lib/API/helpers.rb', line 34

def readable_time_log(obj)
  "#{'%.2d' % obj['minutes']}m #{'%.2d' % obj['seconds']}s"
end

#sec_to_time(secs) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/API/helpers.rb', line 7

def sec_to_time(secs)
  begin
    hours = secs / 3600
    minutes = (secs / 60 - hours * 60)
    seconds = (secs - (minutes * 60 + hours * 3600))
    {'hours' => hours, 'minutes' => minutes, 'seconds' => seconds}
  rescue Exception => e
    raise e, Status.wtf
  end
end