Sha256: 8aebb9a1582f884d2dbbb8065e9927c89fc073eb8f6dbbf6fd15bb1ac7693e1a

Contents?: true

Size: 1.91 KB

Versions: 6

Compression:

Stored size: 1.91 KB

Contents

# encoding: utf-8
module TokiCLI
  class View
    def total_table(list)
      table = init_table
      table.title = "Your apps monitored by Toki"
      puts table_2(list, table)
      puts "\n"
    end
    def day_table(day, list)
      table = init_table
      table.title = "Your apps monitored by Toki on #{day}"
      puts table_2(list, table)
      puts "\n"
    end
    def range_table(day1, day2, list)
      table = init_table
      table.title = "Your apps monitored by Toki between #{day1} and #{day2}"
      puts table_2(list, table)
      puts "\n"
    end
    def hits_table(list)
      table = init_table
      table.title = "Your top apps monitored by Toki"
      puts table2_index(list, table)
      puts "\n"
    end
    def app_table(asked, app_data)
      table = init_table
      table.style = { :width => 100 }
      table.title = "Toki time tracking for '#{asked}' => #{app_data.first[1][:name]}"
      table.headings = ['From', 'To', 'Duration', 'Sync id']
      @index = 0
      @length = app_data.length - 1
      @total = app_data.select {|k,v| k == 'total'}
      app_data.delete('total')
      data = app_data.to_a
      data.sort_by! {|k,v| v[:raw_from] }
      data.each do |id, log|
        @index += 1
        table << ["#{log[:from]}", "#{log[:to]}", "#{log[:duration]}", "#{id}"]
        table << :separator unless @index == @length
      end
      table << :separator
      table << [{ :value => "Total: #{@total['total']}", :colspan => 4, :alignment => :center }]
      puts table
      puts "\n"
    end

    private

    def init_table
      Terminal::Table.new do |t|
        t.style = { :width => 75 }
      end
    end
    def table_2(list, table)
      list.each do |k,v|
        table << ["#{k}", "#{v}"]
      end
      table
    end
    def table2_index(list, table)
      list.each.with_index(1) do |obj,index|
        table << ["#{index}", "#{obj[0]}", "#{obj[1]}"]
      end
      table
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
TokiCLI-0.0.9 lib/TokiCLI/view.rb
TokiCLI-0.0.8 lib/TokiCLI/view.rb
TokiCLI-0.0.7 lib/TokiCLI/view.rb
TokiCLI-0.0.6 lib/TokiCLI/view.rb
TokiCLI-0.0.5 lib/TokiCLI/view.rb
TokiCLI-0.0.4 lib/TokiCLI/view.rb