Class: TimeCop::Accountability
- Inherits:
-
Object
- Object
- TimeCop::Accountability
- Defined in:
- lib/time_cop/accountability.rb
Constant Summary collapse
- DAYS_PER_WEEK =
5.0
- QUARTERLY_PERIODS =
{ q1: [{month: 1, day: 1}, {month: 3, day: 31}], q2: [{month: 4, day: 1}, {month: 6, day: 30}], q3: [{month: 7, day: 1}, {month: 9, day: 30}], q4: [{month: 10, day: 1}, {month: 12, day: 31}] }
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#date ⇒ Object
readonly
Returns the value of attribute date.
-
#hours_per_week ⇒ Object
readonly
Returns the value of attribute hours_per_week.
-
#report_builder ⇒ Object
readonly
Returns the value of attribute report_builder.
-
#today ⇒ Object
readonly
Returns the value of attribute today.
Instance Method Summary collapse
- #account ⇒ Object
- #current_hours_delta ⇒ Object
- #date_from_period(period) ⇒ Object
- #default_user ⇒ Object
- #end_of_quarter_date ⇒ Object
- #expected_quarter_hours ⇒ Object
- #expected_quarter_hours_to_today ⇒ Object
- #fetch_user(email) ⇒ Object
- #get_quarter ⇒ Object
- #hours_per_day ⇒ Object
-
#initialize(username:, password:, subdomain: 'wildland', date: Date.today, today: Date.today, report_builder: nil, email: nil, hours_per_week: 32) ⇒ Accountability
constructor
A new instance of Accountability.
- #print_report ⇒ Object
- #quarterly_hours_delta ⇒ Object
- #quarterly_hours_per_business_day_needed ⇒ Object
- #quarterly_tracked_time_by_user ⇒ Object
- #select_quarter ⇒ Object
- #start_of_quarter_date ⇒ Object
- #summary_hash ⇒ Object
- #total_quarter_days ⇒ Object
- #total_quarter_time_tracked ⇒ Object
- #total_week_days ⇒ Object
- #weekdays_between(start_date, end_date) ⇒ Object
Constructor Details
#initialize(username:, password:, subdomain: 'wildland', date: Date.today, today: Date.today, report_builder: nil, email: nil, hours_per_week: 32) ⇒ Accountability
Returns a new instance of Accountability.
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/time_cop/accountability.rb', line 17 def initialize(username:, password:, subdomain: 'wildland', date: Date.today, today: Date.today, report_builder: nil, email: nil, hours_per_week: 32) @client = Harvest.client(username: username, password: password, subdomain: subdomain) @date = date @today = today @hours_per_week = hours_per_week @report_builder = report_builder || ReportBuilder.new( client: client, user: email ? fetch_user(email) : default_user, start_date: start_of_quarter_date, end_date: end_of_quarter_date ) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
6 7 8 |
# File 'lib/time_cop/accountability.rb', line 6 def client @client end |
#date ⇒ Object (readonly)
Returns the value of attribute date.
6 7 8 |
# File 'lib/time_cop/accountability.rb', line 6 def date @date end |
#hours_per_week ⇒ Object (readonly)
Returns the value of attribute hours_per_week.
6 7 8 |
# File 'lib/time_cop/accountability.rb', line 6 def hours_per_week @hours_per_week end |
#report_builder ⇒ Object (readonly)
Returns the value of attribute report_builder.
6 7 8 |
# File 'lib/time_cop/accountability.rb', line 6 def report_builder @report_builder end |
#today ⇒ Object (readonly)
Returns the value of attribute today.
6 7 8 |
# File 'lib/time_cop/accountability.rb', line 6 def today @today end |
Instance Method Details
#account ⇒ Object
35 36 37 |
# File 'lib/time_cop/accountability.rb', line 35 def account client.account end |
#current_hours_delta ⇒ Object
103 104 105 |
# File 'lib/time_cop/accountability.rb', line 103 def current_hours_delta total_quarter_time_tracked - expected_quarter_hours_to_today end |
#date_from_period(period) ⇒ Object
47 48 49 |
# File 'lib/time_cop/accountability.rb', line 47 def date_from_period(period) Date.new(date.year, period[:month], period[:day]) end |
#default_user ⇒ Object
43 44 45 |
# File 'lib/time_cop/accountability.rb', line 43 def default_user account.who_am_i end |
#end_of_quarter_date ⇒ Object
71 72 73 |
# File 'lib/time_cop/accountability.rb', line 71 def end_of_quarter_date date_from_period(get_quarter[1]) end |
#expected_quarter_hours ⇒ Object
95 96 97 |
# File 'lib/time_cop/accountability.rb', line 95 def expected_quarter_hours total_week_days.to_f * hours_per_day end |
#expected_quarter_hours_to_today ⇒ Object
99 100 101 |
# File 'lib/time_cop/accountability.rb', line 99 def expected_quarter_hours_to_today weekdays_between(start_of_quarter_date, today < end_of_quarter_date ? Date.today : end_of_quarter_date) * hours_per_day end |
#fetch_user(email) ⇒ Object
39 40 41 |
# File 'lib/time_cop/accountability.rb', line 39 def fetch_user(email) client.users.find(email) end |
#get_quarter ⇒ Object
63 64 65 |
# File 'lib/time_cop/accountability.rb', line 63 def get_quarter select_quarter.first[1] end |
#hours_per_day ⇒ Object
31 32 33 |
# File 'lib/time_cop/accountability.rb', line 31 def hours_per_day @hours_per_week / DAYS_PER_WEEK end |
#print_report ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/time_cop/accountability.rb', line 134 def print_report puts "Quarter Period: #{start_of_quarter_date} #{end_of_quarter_date}" puts "Hours Per Week: #{@hours_per_week}" puts "Current Surplus(+)/Deficit(-): #{current_hours_delta.round(2)}" puts "Quarterly Hour Target: #{expected_quarter_hours.round(2)}" puts "Current Quarterly Charged Hours: #{total_quarter_time_tracked.round(2)}" if (@date.year == Date.today.year) puts "Total Hours Needed By End Of Quarter: #{quarterly_hours_delta.round(2)}" puts "Hours Per Business Day Average Needed To Reach Goal: #{quarterly_hours_per_business_day_needed.round(2)}" end end |
#quarterly_hours_delta ⇒ Object
107 108 109 |
# File 'lib/time_cop/accountability.rb', line 107 def quarterly_hours_delta expected_quarter_hours - total_quarter_time_tracked end |
#quarterly_hours_per_business_day_needed ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/time_cop/accountability.rb', line 111 def quarterly_hours_per_business_day_needed if weekdays_between(today, end_of_quarter_date) == 0 quarterly_hours_delta else quarterly_hours_delta / weekdays_between(today, end_of_quarter_date).to_f end end |
#quarterly_tracked_time_by_user ⇒ Object
75 76 77 |
# File 'lib/time_cop/accountability.rb', line 75 def quarterly_tracked_time_by_user @quarterly_tracked_time_by_user ||= report_builder.generate end |
#select_quarter ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/time_cop/accountability.rb', line 51 def select_quarter QUARTERLY_PERIODS.select do |quarter, range| start_of_range = range[0] end_of_range = range[1] start_date_of_range = date_from_period(start_of_range) end_date_of_range = date_from_period(end_of_range) (date >= start_date_of_range) && (date <= end_date_of_range) end end |
#start_of_quarter_date ⇒ Object
67 68 69 |
# File 'lib/time_cop/accountability.rb', line 67 def start_of_quarter_date date_from_period(get_quarter[0]) end |
#summary_hash ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/time_cop/accountability.rb', line 119 def summary_hash { quarter: { start: start_of_quarter_date, end: end_of_quarter_date, weekdays_in_quarter: weekdays_between(@report_builder.start_date, @report_builder.end_date) }, hours_per_week: @hours_per_week, hours: { charged: total_quarter_time_tracked, needed: expected_quarter_hours, } } end |
#total_quarter_days ⇒ Object
83 84 85 |
# File 'lib/time_cop/accountability.rb', line 83 def total_quarter_days (end_of_quarter_date - start_of_quarter_date).to_i end |
#total_quarter_time_tracked ⇒ Object
79 80 81 |
# File 'lib/time_cop/accountability.rb', line 79 def total_quarter_time_tracked quarterly_tracked_time_by_user.map { |t| t.hours }.reduce(0, :+) end |
#total_week_days ⇒ Object
91 92 93 |
# File 'lib/time_cop/accountability.rb', line 91 def total_week_days weekdays_between(start_of_quarter_date, end_of_quarter_date) end |
#weekdays_between(start_date, end_date) ⇒ Object
87 88 89 |
# File 'lib/time_cop/accountability.rb', line 87 def weekdays_between(start_date, end_date) (start_date..end_date).select{|d| (1..5).include?(d.wday)}.size end |