Class: Dude::Report

Inherits:
Object
  • Object
show all
Includes:
Settings
Defined in:
lib/dude/report.rb

Constant Summary

Constants included from Settings

Settings::CONFIG_FILE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Settings

#file, #read, #settings

Constructor Details

#initialize(report_json) ⇒ Report

Returns a new instance of Report.



9
10
11
# File 'lib/dude/report.rb', line 9

def initialize(report_json)
  @report = JSON.parse(report_json.body)
end

Instance Attribute Details

#reportObject (readonly)

Returns the value of attribute report.



7
8
9
# File 'lib/dude/report.rb', line 7

def report
  @report
end

Instance Method Details

#days_without_weekendsObject



21
22
23
# File 'lib/dude/report.rb', line 21

def days_without_weekends
  @days_without_weekends ||= report['week_totals'][0..Time.now.wday - 1].compact.count
end

#hours_without_weekendsObject



30
31
32
# File 'lib/dude/report.rb', line 30

def hours_without_weekends
  @hours_without_weekends ||= settings['HOURS_PER_WEEK'].to_i - weekends * settings['HOURS_PER_DAY'].to_i
end

#seconds_for_todayObject



34
35
36
# File 'lib/dude/report.rb', line 34

def seconds_for_today
  days_without_weekends * settings['HOURS_PER_DAY'].to_i * 3600
end

#today_time_workedObject



17
18
19
# File 'lib/dude/report.rb', line 17

def today_time_worked
  @today_time_worked ||= report['week_totals'].map {|a| a.nil? ? 0 : a / 1000}[Time.now.wday - 1]
end

#week_time_workedObject



13
14
15
# File 'lib/dude/report.rb', line 13

def week_time_worked
  @time_worked ||= report['total_grand'] / 1000
end

#weekendsObject



25
26
27
28
# File 'lib/dude/report.rb', line 25

def weekends
  @weekends ||= report['week_totals'][0..Time.now.wday - 1].
    select { |a| a.nil? }.count
end