class TheFox::Timr::Command::LogCommand

By default this Command prints all todays Tracks.

Man page: timr-log(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/log_command.rb, line 20
def initialize(argv = Array.new)
    super()
    
    @help_opt = false
    
    @from_opt = nil
    @to_opt = nil
    
    @start_date = nil
    @end_date = nil
    
    @start_time = nil
    @end_time = nil
    
    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 '-s', '--from'
            @from_opt = Time.parse(argv.shift)
        when '-e', '--to'
            @to_opt = Time.parse(argv.shift)
        
        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 '--sd', '--start-date'
            @start_date = Time.parse(argv.shift)
        when '--ed', '--end-date'
            @end_date = Time.parse(argv.shift)
        when '--st', '--start-time'
            @start_time = Time.parse(argv.shift)
        when '--et', '--end-time'
            @end_time = Time.parse(argv.shift)
        
        else
            raise LogCommandError, "Unknown argument '#{arg}'. See 'timr log --help'."
        end
    end
    
    @daytime_filter = false
    if @start_date && @end_date && @start_time && @end_time
        @from_opt = Time.parse("#{@start_date.strftime('%F')} #{@start_time.strftime('%T')}")
        @to_opt   = Time.parse("#{@end_date.strftime('%F')} #{@end_time.strftime('%T')}")
        
        @daytime_filter = true
    end
    
    today = Date.today
    unless @from_opt
        @from_opt = Time.new(today.year, today.month, today.day, 0, 0, 0)
    end
    unless @to_opt
        @to_opt = Time.new(today.year, today.month, today.day, 23, 59, 59)
    end
    
    @filter_options = {:from => @from_opt, :to => @to_opt}
end

Public Instance Methods

run() click to toggle source

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

# File lib/timr/command/log_command.rb, line 93
def run
    if @help_opt
        help
        return
    end
    
    @timr = Timr.new(@cwd)
    
    print_small_table
end