Class: Twstats::TimeSheetExport

Inherits:
Object
  • Object
show all
Defined in:
lib/twstats/timesheet_export.rb

Instance Method Summary collapse

Constructor Details

#initialize(csv, prompt) ⇒ TimeSheetExport

Returns a new instance of TimeSheetExport.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/twstats/timesheet_export.rb', line 6

def initialize(csv, prompt)
  @prompt = prompt
  @rows = []
  # Filter by billable and not billed
  csv.logs.select{|x| x.billable && !x.invoiced}.sort_by{|x| x.start_date}.each do |log|
    @rows << {
      date: log.date.strftime('%m/%d/%Y'),
      who: public_name(log.who),
      description: log.description,
      time: log.decimal_time,
      proj: log.project
    }
  end
  @proj = csv.projects

  # Ask the user how to configure the export
  if csv.projects.size > 1
    @proj = @prompt.multi_select 'I have found more than one project in the CSV file, which ones do you want to export for timesheet?' do |menu|
      menu.choices csv.projects
      menu.default *[*1..csv.projects.size] # Generates an array from 1 to the maximum index of the projects array
    end
  end
end

Instance Method Details

#executeObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/twstats/timesheet_export.rb', line 30

def execute
  puts "Copy each column below into the proper column of the spreadsheet"
  columns = [:date, :who, :description, :time]
  columns.each do |column|
    puts "***********".bright.blue
    puts column.to_s.capitalize.bright.blue
    puts "***********".bright.blue
    @rows.each do |row|
      next unless @proj.include? row[:proj]
      puts "#{row[column]}"
    end
  end
  puts "******* Total amount of time billed *******".bright.blue
  puts "This amounts to #{@rows.inject(0) { |sum, x| sum += x[:time].to_f }} hours.".bright
  puts "Check with the amount of hours to be billed to see they match".bright
end

#public_name(name) ⇒ Object



47
48
49
# File 'lib/twstats/timesheet_export.rb', line 47

def public_name(name)
  name.split[0]
end