# encoding: utf-8 module TokiCLI class View def total_table(list) table = init_table table.title = "Your apps monitored by Toki" list.each do |k,v| table << ["#{k}", "#{v}"] end table end def hits_table(list) table = init_table table.title = "Your top apps monitored by Toki" list.each.with_index(1) do |obj,index| table << ["#{index}", "#{obj[0]}", "#{obj[1]}"] end table 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 }] table end private def init_table Terminal::Table.new do |t| t.style = { :width => 75 } end end end end