class TheFox::Timr::Command::ReportCommand

This Command is very similar to LogCommand. By default it prints all Tasks of the current month.

Man page: timr-report(1)

Constants

MAN_PATH

Path to man page.

Public Class Methods

new(argv = Array.new) click to toggle source
Calls superclass method TheFox::Timr::Command::BasicCommand.new
# File lib/timr/command/report_command.rb, line 19
def initialize(argv = Array.new)
    super()
    
    @help_opt = false
    @tasks_opt = false
    @tracks_opt = false
    @from_opt = nil
    @to_opt = nil
    @billed_opt = false
    @unbilled_opt = false
    @format_opt = nil
    @csv_opt = nil
    @force_opt = false
    
    loop_c = 0 # Limit the loop.
    while loop_c < 1024 && argv.length > 0
        loop_c += 1
        arg = argv.shift
        
        case arg
        when '-h', '--help'
            @help_opt = true
        
        when '-d', '--day'
            @from_opt, @to_opt = DateTimeHelper.parse_day_argv(argv)
        when '-m', '--month'
            @from_opt, @to_opt = DateTimeHelper.parse_month_argv(argv)
        when '-y', '--year'
            @from_opt, @to_opt = DateTimeHelper.parse_year_argv(argv)
        
        when '-a', '--all'
            @from_opt = Time.parse('1970-01-01 00:00:00')
            @to_opt   = Time.parse('2099-12-31 23:59:59')
        
        when '--tasks'
            @tasks_opt = true
        when '-t', '--tracks'
            @tracks_opt = true
        
        when '--billed'
            @billed_opt = true
        when '--unbilled'
            @unbilled_opt = true
        
        when '--format'
            @format_opt = argv.shift
        
        when '--csv'
            @csv_opt = argv.shift
            if !@csv_opt
                raise ReportCommandError, 'Invalid value for --csv option.'
            end
        when '-f', '--force' # -f inofficial, maybe used for --file?
            @force_opt = true
        
        else
            raise ReportCommandError, "Unknown argument '#{arg}'. See 'timr report --help'."
        end
    end
    
    today = Date.today
    unless @from_opt
        @from_opt = Time.new(today.year, today.month, 1, 0, 0, 0)
    end
    unless @to_opt
        month_end = Date.new(today.year, today.month, -1)
        @to_opt = Time.new(today.year, today.month, month_end.day, 23, 59, 59)
    end
    
    @billed_resolved_opt = nil
    if @billed_opt || @unbilled_opt
        if @billed_opt
            @billed_resolved_opt = true
        elsif @unbilled_opt
            @billed_resolved_opt = false
        end
    end
    
    @filter_options = {
        :format => '%y-%m-%d %H:%M',
        :from => @from_opt,
        :to => @to_opt,
        :billed => @billed_resolved_opt,
    }
    @csv_filter_options = {
        :format => '%F %T %z',
        :from => @from_opt,
        :to => @to_opt,
    }
    
    # Used by
    #  print_formatted_task_list
    #  print_formatted_track_list
    @format_options = {
        :format => @format_opt,
        :billed => @billed_resolved_opt,
    }
    
    if @csv_opt
        if @csv_opt == '-'
            # OK
        else
            @csv_opt = Pathname.new(@csv_opt).expand_path
        end
    end
end

Public Instance Methods

run() click to toggle source

See TheFox::Timr::Command::BasicCommand#run.

# File lib/timr/command/report_command.rb, line 127
def run
    if @help_opt
        help
        return
    end
    
    @timr = Timr.new(@cwd)
    
    if @csv_opt
        if @tasks_opt
            export_tasks_csv
        elsif @tracks_opt
            export_tracks_csv
        else
            export_tasks_csv
        end
    elsif @format_opt
        if @tasks_opt
            print_formatted_task_list
        elsif @tracks_opt
            print_formatted_track_list
        else
            print_formatted_task_list
        end
    else
        if @tasks_opt
            print_task_table
        elsif @tracks_opt
            print_track_table
        else
            print_task_table
        end
    end
end