class Tlog::Command::Display
Public Instance Methods
description()
click to toggle source
# File lib/tlog/command/display.rb, line 8 def description "displays information about time logs. command options contrain which time logs are displayed" end
execute(input, output)
click to toggle source
# File lib/tlog/command/display.rb, line 12 def execute(input, output) display(input.args[0], input.options, output) end
log_goal_valid(log, thresholds)
click to toggle source
Methods that filter which logs should be displayed
# File lib/tlog/command/display.rb, line 39 def log_goal_valid(log, thresholds) goal_threshold = thresholds[:goal] goal_threshold = ChronicDuration.parse(goal_threshold) return false unless log.goal goal_threshold >= log.goal ? valid = true : valid = false valid end
log_owners_valid(log, thresholds)
click to toggle source
# File lib/tlog/command/display.rb, line 47 def log_owners_valid(log, thresholds) owners = thresholds[:owners] owners.each do |owner| return true if log.owner == owner end false end
log_points_valid(log, thresholds)
click to toggle source
# File lib/tlog/command/display.rb, line 55 def log_points_valid(log, thresholds) points_value = thresholds[:points] log.points >= points_value ? valid = true : valid = false valid end
log_states_valid(log, thresholds)
click to toggle source
# File lib/tlog/command/display.rb, line 61 def log_states_valid(log, thresholds) states = thresholds[:states] states.each do |state| return true if log.state.downcase == state.downcase end false end
name()
click to toggle source
# File lib/tlog/command/display.rb, line 4 def name "display" end
options(parser, options)
click to toggle source
# File lib/tlog/command/display.rb, line 16 def options(parser, options) parser.banner = "usage: tlog display #{$0} [options]" parser.on("-g", "--goal <goal_threshold>") do |goal| options[:goal] = goal end parser.on("-o", "--owner a,b,c", Array, "Array of owners to display") do |owners| options[:owners] = owners end parser.on("-p", "--points <points_threshold>") do |points| options[:points] = points.to_i end parser.on("-s", "--state a,b,c", Array, "Array of states to display") do |states| options[:states] = states end end
Private Instance Methods
display(log_name, options, output)
click to toggle source
# File lib/tlog/command/display.rb, line 71 def display(log_name, options, output) storage.in_branch do |wd| if storage.all_log_dirs if log_name display_log(log_name, options, output) else display_all(options, output) end else output.line("No time logs yet"); end end end
display_all(options, output)
click to toggle source
# File lib/tlog/command/display.rb, line 104 def display_all(options, output) storage.all_log_dirs.each do |log_path| log_basename = log_path.basename.to_s display_log(log_basename, options, output) end end
display_entries(entries, output)
click to toggle source
# File lib/tlog/command/display.rb, line 122 def display_entries(entries, output) if entries.size > 0 entries.each do |entry| out_str = "\t%-4s %16s%12s %s" % [ date_time_format.timestamp(entry.time[:start]), date_time_format.timestamp(entry.time[:end]), seconds_format.duration(entry.length.to_s), entry.description, ] output.line(out_str) end end end
display_log(log_name, options, output)
click to toggle source
# File lib/tlog/command/display.rb, line 85 def display_log(log_name, options, output) log = storage.require_log(log_name) raise Tlog::Error::CommandInvalid, "Time log '#{log_name}' does not exist" unless log log_length = log.goal_length entries = log.entries if storage.start_time_string && is_current_log_name?(log_name) start_time = Time.parse(storage.start_time_string) end return unless log_valid?(log, options) # Print out time log information print_log_info(log, output) print_header(output) print_current(log_name, log_length, start_time, output) display_entries(entries, output) if entries print_footer(log, log_length, output) end
is_current_log_name?(log_name)
click to toggle source
# File lib/tlog/command/display.rb, line 191 def is_current_log_name?(log_name) if storage.current_log_name == log_name true else false end end
log_valid?(log, thresholds = {})
click to toggle source
# File lib/tlog/command/display.rb, line 111 def log_valid?(log, thresholds = {}) thresholds.each do |key, value| attribute_value = key.to_s log_valid_method = "log_#{attribute_value}_valid" if respond_to?(log_valid_method) return false unless self.send(log_valid_method, log, thresholds) end end true end
print_current(log_name, log_length, current_start_time, output)
click to toggle source
should be added to entries array, not its own seperate thing
# File lib/tlog/command/display.rb, line 173 def print_current(log_name, log_length, current_start_time, output) if is_current_log_name?(log_name) formatted_length = seconds_format.duration storage.time_since_start out_str = out_str = "\t%-4s %16s%14s %s" % [ date_time_format.timestamp(current_start_time), nil, formatted_length, storage.cur_entry_description, ] output.line(out_str) storage.time_since_start end end
print_header(output)
click to toggle source
# File lib/tlog/command/display.rb, line 142 def print_header(output) output.line("\tStart End Duration Description") end
print_log_info(log, output)
click to toggle source
# File lib/tlog/command/display.rb, line 155 def print_log_info(log, output) out_str = "Log: #{log.name}\nState: #{log.state}\nPoints: #{log.points}\nOwner: #{log.owner}" output.line_yellow(out_str) end
print_time_left(log, output)
click to toggle source
# File lib/tlog/command/display.rb, line 160 def print_time_left(log, output) if log.goal log_goal = log.goal if (storage.current_log_name == log.name) current_time = Time.now - storage.cur_start_time log_goal -= current_time.to_i end log_goal = 0 if log_goal < 0 output.line_red("\tTime left: %39s" % seconds_format.duration(log_goal)) end end
print_total(log, output)
click to toggle source
# File lib/tlog/command/display.rb, line 146 def print_total(log, output) #output.line("-") * 52 duration = log.duration if storage.current_log_name == log.name duration += storage.time_since_start end output.line("\tTotal%45s " % seconds_format.duration(duration)) end
update_log_length(log_length)
click to toggle source
# File lib/tlog/command/display.rb, line 187 def update_log_length(log_length) log_length - storage.time_since_start if log_length end