Class: TheFox::Timr::Command::LogCommand

Inherits:
BasicCommand show all
Includes:
Error, Helper
Defined in:
lib/timr/command/log_command.rb

Overview

By default this Command prints all todays [Tracks](TheFox::Timr::Model::Track).

Man page: [timr-log(1)](../../../../man/timr-log.1.html)

Constant Summary collapse

MAN_PATH =

Path to man page.

'man/timr-log.1'

Instance Attribute Summary

Attributes inherited from BasicCommand

#cwd

Instance Method Summary collapse

Methods inherited from BasicCommand

create_command_from_argv, get_command_class_by_name, #shutdown

Constructor Details

#initialize(argv = Array.new) ⇒ LogCommand

Returns a new instance of LogCommand.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# 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

Instance Method Details

#runObject

See BasicCommand#run.



93
94
95
96
97
98
99
100
101
102
# 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