Class: Timeshit::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/timeshit/cli.rb

Constant Summary collapse

CSV_OPTS =
{
  col_sep: ';',
  quote_char:'"',
  headers: true,
  force_quotes: true,
  header_converters: :symbol
}.freeze

Instance Method Summary collapse

Instance Method Details

#read(filename) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/timeshit/cli.rb', line 20

def read(filename)
  filter = options[:filter]
  rate = options[:rate] || 1297.0
  total = 0.0

  CSV.open(filename, 'r:bom|utf-8', CSV_OPTS) do |csv|
    csv.each do |row|
      code = row[:dimensjon_4]
      filtered_out = filter && !code.include?(filter)

      next if code.empty? || filtered_out

      hrs = row[:sum].split(":")[0].to_i
      min = row[:sum].split(":")[1].to_i
      sum = hrs+(min.to_i/60.0).round(2)
      puts "    #{row[:dato]}:    #{code[/\d+/]}     #{sum}"
      total+=sum
    end
  end

  puts "------------------------------------"
  puts "             rate: #{rate}"
  puts "        total hrs: #{total.round(2)}"
  puts "   total earnings: #{(total * rate).round(2)}"
  puts "         your cut: #{(total * rate * 0.6).round(2)}"
  puts "        after tax: #{(total * rate * 0.6 * 0.6).round(2)}"
  puts "   after vacation: #{(total * rate * 0.6 * 0.6 * 0.88).round(2)}"
  puts "------------------------------------"
end