myworklog 1.1.1 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/myworklog +1 -1
- data/lib/list_strategy.rb +39 -0
- data/lib/printer.rb +15 -0
- data/lib/{worklog_cli.rb → work_log_cli.rb} +29 -26
- data/lib/work_log_controller.rb +12 -4
- data/lib/work_log_file_dao.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6fc3e032e7220ac9749c9644ee0f1f238e0492043f89288afdf7c443aacc5fcc
|
4
|
+
data.tar.gz: 9ceac43973316b614a5939b04918e12b8a3295af91e328f6a1ea5588e51a6edc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07b24c7a42117bc3e0f00c65ac1f5443a1785584a24583538570c0a585353bd2c18d365917a17780e874277ed938a73d0999d9bda54aadc66152447ab3cb3a71
|
7
|
+
data.tar.gz: 430bab758bd15ba3efcabadbf69a287bc6ead53a27be26e3ac000850ba7e3cd347c5dff7baf64e1bfa17ef2806e6377041b429b44c0917ab383f3235615456c1
|
data/bin/myworklog
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'work_log_controller'
|
4
|
+
|
5
|
+
class ListStrategy
|
6
|
+
attr_reader :date, :month, :year
|
7
|
+
|
8
|
+
def initialize(date, month, year)
|
9
|
+
@date = date
|
10
|
+
@month = month
|
11
|
+
@year = year
|
12
|
+
end
|
13
|
+
|
14
|
+
def execute
|
15
|
+
return list_by_month_and_year if @month && @year
|
16
|
+
return list_by_month_current_year if @month && @year.nil?
|
17
|
+
return list_by_year if @month.nil? && @year
|
18
|
+
|
19
|
+
list_by_date
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def list_by_date
|
25
|
+
WorkLogController.new.list(@date)
|
26
|
+
end
|
27
|
+
|
28
|
+
def list_by_month_and_year
|
29
|
+
WorkLogController.new.find_by_month_and_year(@month, @year)
|
30
|
+
end
|
31
|
+
|
32
|
+
def list_by_month_current_year
|
33
|
+
WorkLogController.new.find_by_month_and_year(@month, Date.today.year)
|
34
|
+
end
|
35
|
+
|
36
|
+
def list_by_year
|
37
|
+
WorkLogController.new.find_by_year(@year)
|
38
|
+
end
|
39
|
+
end
|
data/lib/printer.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Printer
|
4
|
+
def print(work_log_list)
|
5
|
+
puts ''
|
6
|
+
if work_log_list.empty?
|
7
|
+
puts 'Work log(s) not found'
|
8
|
+
else
|
9
|
+
work_log_list.each do |work_log|
|
10
|
+
puts "#{work_log.id} | #{work_log}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
puts ''
|
14
|
+
end
|
15
|
+
end
|
@@ -3,7 +3,9 @@
|
|
3
3
|
require 'thor'
|
4
4
|
require 'date'
|
5
5
|
require 'rubygems'
|
6
|
-
|
6
|
+
require 'work_log_controller'
|
7
|
+
require 'list_strategy'
|
8
|
+
require 'printer'
|
7
9
|
|
8
10
|
DATE_FORMAT = 'DD/MM/YYYY'
|
9
11
|
|
@@ -25,39 +27,36 @@ class WorkLogCli < Thor
|
|
25
27
|
|
26
28
|
Availble options:
|
27
29
|
|
30
|
+
with [DATE], prints the work logged for the given date in DD/MM/YYYY
|
31
|
+
|
28
32
|
With -m option, prints all the work logs for the specified month, assumes the current year
|
29
33
|
|
30
34
|
With -m and -y options, prints all the work logs for the specified month and year
|
31
35
|
|
32
36
|
With -y option, prints all the work logs for the specified year
|
33
37
|
|
38
|
+
With --all option, prints all the work logs from the database
|
39
|
+
|
34
40
|
Usage examples:
|
35
41
|
|
36
|
-
`myworklog
|
42
|
+
`myworklog 10/10/2019` Will print all the work logs for the given date
|
43
|
+
|
44
|
+
`myworklog -m 2` Will print all the work logs loggedi n Februrary of the current year
|
37
45
|
|
38
46
|
`myworklog -m 2 -y 2019` Will print all the work logs logged in Februrary of 2019
|
39
47
|
|
40
48
|
`myworklog -y 2020` Will print all the work logs logged in 2020
|
41
49
|
|
50
|
+
`myworklog --all`
|
51
|
+
|
42
52
|
LONGDESC
|
43
53
|
options m: :numeric
|
44
54
|
options y: :numeric
|
55
|
+
options all: :string
|
45
56
|
def list(date = '')
|
46
|
-
|
47
|
-
print(WorkLogController.new.find_by_month_and_year(options[:m], options[:y]))
|
48
|
-
elsif options[:m] && options[:y].nil?
|
49
|
-
print(WorkLogController.new.find_by_month_and_year(options[:m], Date.today.year))
|
50
|
-
elsif options[:m].nil? && options[:y]
|
51
|
-
print(WorkLogController.new.find_by_year(options[:y]))
|
52
|
-
else
|
53
|
-
print(WorkLogController.new.list(date))
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
desc 'list_all', 'prints all the work logs'
|
57
|
+
return print(WorkLogController.new.list_all) if options[:all]
|
58
58
|
|
59
|
-
|
60
|
-
print(WorkLogController.new.list_all)
|
59
|
+
print(ListStrategy.new(date, options[:m], options[:y]).execute)
|
61
60
|
end
|
62
61
|
|
63
62
|
desc 'delete [ID]', 'Deletes the work log by ID. You can use the `list` command to retrieve the ID'
|
@@ -65,7 +64,7 @@ class WorkLogCli < Thor
|
|
65
64
|
def delete(id)
|
66
65
|
WorkLogController.new.delete(id)
|
67
66
|
puts "Work log with #{id} ID has been deleted!"
|
68
|
-
rescue
|
67
|
+
rescue ArgumentError => e
|
69
68
|
puts e
|
70
69
|
end
|
71
70
|
|
@@ -78,15 +77,19 @@ class WorkLogCli < Thor
|
|
78
77
|
|
79
78
|
private
|
80
79
|
|
80
|
+
def list_by_year(year)
|
81
|
+
print(WorkLogController.new.find_by_year(year))
|
82
|
+
end
|
83
|
+
|
84
|
+
def list_by_month(month)
|
85
|
+
print(WorkLogController.new.find_by_month_and_year(month, Date.today.year))
|
86
|
+
end
|
87
|
+
|
88
|
+
def list_by_month_and_year(month, year)
|
89
|
+
print(WorkLogController.new.find_by_month_and_year(month, year))
|
90
|
+
end
|
91
|
+
|
81
92
|
def print(work_log_list)
|
82
|
-
|
83
|
-
if work_log_list.empty?
|
84
|
-
puts 'Work log(s) not found'
|
85
|
-
else
|
86
|
-
work_log_list.each do |work_log|
|
87
|
-
puts "#{work_log.id} | #{work_log}"
|
88
|
-
end
|
89
|
-
end
|
90
|
-
puts ''
|
93
|
+
Printer.new.print(work_log_list)
|
91
94
|
end
|
92
95
|
end
|
data/lib/work_log_controller.rb
CHANGED
@@ -7,15 +7,19 @@ require_relative 'work_log'
|
|
7
7
|
|
8
8
|
class WorkLogController
|
9
9
|
def add_work_log(date, description)
|
10
|
+
if description.nil? || description.empty?
|
11
|
+
raise ArgumentError, 'Description must not be empty'
|
12
|
+
end
|
13
|
+
|
10
14
|
WorkLogFileDao.new.save(create_work_log(date, description))
|
11
15
|
end
|
12
16
|
|
13
17
|
def list(date)
|
14
|
-
WorkLogFileDao.new.list(parse_date(date))
|
18
|
+
sort_by_date(WorkLogFileDao.new.list(parse_date(date)))
|
15
19
|
end
|
16
20
|
|
17
21
|
def list_all
|
18
|
-
WorkLogFileDao.new.list_all
|
22
|
+
sort_by_date(WorkLogFileDao.new.list_all)
|
19
23
|
end
|
20
24
|
|
21
25
|
def delete(id)
|
@@ -23,11 +27,11 @@ class WorkLogController
|
|
23
27
|
end
|
24
28
|
|
25
29
|
def find_by_month_and_year(month, year)
|
26
|
-
WorkLogFileDao.new.find_by_month_and_year(month, year)
|
30
|
+
sort_by_date(WorkLogFileDao.new.find_by_month_and_year(month, year))
|
27
31
|
end
|
28
32
|
|
29
33
|
def find_by_year(year)
|
30
|
-
WorkLogFileDao.new.find_by_year(year)
|
34
|
+
sort_by_date(WorkLogFileDao.new.find_by_year(year))
|
31
35
|
end
|
32
36
|
|
33
37
|
private
|
@@ -45,4 +49,8 @@ class WorkLogController
|
|
45
49
|
Date.strptime(date, '%d/%m/%Y')
|
46
50
|
end
|
47
51
|
end
|
52
|
+
|
53
|
+
def sort_by_date(work_log_list)
|
54
|
+
work_log_list.sort_by(&:date)
|
55
|
+
end
|
48
56
|
end
|
data/lib/work_log_file_dao.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: myworklog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gyowanny Queiroz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-02-
|
11
|
+
date: 2020-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Log your work from cmd and keep track of what you have done... just in
|
14
14
|
case your boss ask
|
@@ -20,10 +20,12 @@ extensions: []
|
|
20
20
|
extra_rdoc_files: []
|
21
21
|
files:
|
22
22
|
- bin/myworklog
|
23
|
+
- lib/list_strategy.rb
|
24
|
+
- lib/printer.rb
|
23
25
|
- lib/work_log.rb
|
26
|
+
- lib/work_log_cli.rb
|
24
27
|
- lib/work_log_controller.rb
|
25
28
|
- lib/work_log_file_dao.rb
|
26
|
-
- lib/worklog_cli.rb
|
27
29
|
homepage: http://rubygems.org/gems/myworklog
|
28
30
|
licenses:
|
29
31
|
- MIT
|