Sha256: b3872ca8c16aa02f89da842203545c546593d0d849cc0cb3c6dd95248a333acc

Contents?: true

Size: 1.65 KB

Versions: 1

Compression:

Stored size: 1.65 KB

Contents

require 'tty-prompt'

require_relative 'csv_reader'

module Twstats
  class Runner
    def initialize
      # Load interactive console
      @prompt = TTY::Prompt.new
      puts WELLCOME_MESSAGE
      # Ask for the csv file
      file = @prompt.ask('Specify the CSV file from a Teamwork time log export', default: 'exportTimeLog.csv') do |input|
        input.modify :chomp
      end
      @csv = CSVReader.new(file)
      loop do
        option = @prompt.select("Choose an option", Twstats::MENU_CHOICES)
        case option
          when 0
            show_stats_menu
          when 1
            show_info
          when 2
            break
          else
            puts 'Option not recognized!'
        end
      end
    end

    def show_stats_menu
      loop do
        option = @prompt.select("Select what time logging stats you want to see", Twstats::STATS_MENU_CHOICES)
        case option
          when 0
            show_stats :projects
          when 1
            show_stats :people
          when 2
            show_stats :tags
          when 3
            show_bil_vs_non_stats
          when 4
            show_full_stats
          when 5
            return
          else
            puts 'Option not recognized'
        end
      end
    end

    def show_stats(obj)
      puts "Time logged vs #{obj.to_s}:"
      toshow = {}
      max = 0
      @csv.send(obj).each do |element|
        toshow[element] = @csv.get_total_time(obj, element).round(2)
        max = element.size if max < element.size
      end
      toshow.sort_by{ |k,v| v}.reverse.to_h.each do |k,v|
        puts " - #{k.ljust(max,' ')} -> #{v}"
      end
    end

    def show_info

    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
twstats-0.1.4 lib/twstats/runner.rb