myworklog 1.1.0 → 1.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bdd92d2d822c08464ccc93918c903303973f5e1f958fc9ac166e483877338178
4
- data.tar.gz: f49931374165a57565bbd2c3faba90194b1b7ac6ce4bdcb7afbbb4a3b42dc8ab
3
+ metadata.gz: 694b96c440effe98b20dea018f6bf98f2eff3c93efaa57733a8e2db001531225
4
+ data.tar.gz: cdf1f7fd2db0bed741c68bb3c99ed2af1dd99b7c12793c35c68974cd5fa7a2c5
5
5
  SHA512:
6
- metadata.gz: 65ceb6290ef9a952f1167f6dd5241d155a871945de1ef4784761c2afd0da7ccab85b95f8be2ff0d1da40fdc2948745dce584317db41c745734827e7e4567b809
7
- data.tar.gz: 2e72b7c4523afe01315125b4a3031b71052587a5b8034429b6bd34ea08101812160a1bbae7f6495bb4d75558dccd397292ed2bfbeae3770d614221700994c564
6
+ metadata.gz: 41dcf2cd09f51b0667e32b6137aaf360b3aaa975f1f4809f1cebb81a66f336c997c02b13489f71da0fa705053cb74c88bd5e80ef8a1b19288c79be468cf058d2
7
+ data.tar.gz: 857ffa80fbdc6bb05d2a73d4de1c15ba751085a22d776312243c848b49757ff623990f0bae2ad85001aa2c8051834f0387cd8f2fc23a62869e48a0d157226699
data/lib/work_log.rb CHANGED
@@ -1,13 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class WorkLog
2
- attr_reader :id, :date, :description
4
+ attr_reader :id, :date, :description
3
5
 
4
- def initialize(id, date, description)
5
- @id = id
6
- @date = date
7
- @description = description
8
- end
6
+ def initialize(id, date, description)
7
+ @id = id
8
+ @date = date
9
+ @description = description
10
+ end
9
11
 
10
- def to_s
11
- "#{@date.strftime('%d/%m/%Y')} - #{@description}"
12
- end
13
- end
12
+ def to_s
13
+ "#{@date.strftime('%d/%m/%Y')} - #{@description}"
14
+ end
15
+ end
@@ -1,47 +1,48 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'securerandom'
2
4
  require 'Date'
3
5
  require_relative 'work_log_file_dao'
4
6
  require_relative 'work_log'
5
7
 
6
8
  class WorkLogController
7
-
8
- def add_work_log(date, description)
9
- WorkLogFileDao.new.save(create_work_log(date, description))
10
- end
11
-
12
- def list(date)
13
- WorkLogFileDao.new.list(parse_date(date))
14
- end
15
-
16
- def list_all
17
- WorkLogFileDao.new.list_all
18
- end
19
-
20
- def delete(id)
21
- WorkLogFileDao.new.delete(id)
22
- end
23
-
24
- def find_by_month_and_year(month, year)
25
- WorkLogFileDao.new.find_by_month_and_year(month, year)
26
- end
27
-
28
- def find_by_year(year)
29
- WorkLogFileDao.new.find_by_year(year)
30
- end
31
-
32
- private
33
-
34
- def create_work_log(date, description)
35
- WorkLog.new(SecureRandom.uuid, parse_date(date), description)
36
- end
37
-
38
- def parse_date(date)
39
- if date.nil? || date.empty? || date.downcase == 'today'
40
- Date.today
41
- elsif date.downcase == 'yesterday'
42
- Date.today.prev_day
43
- else
44
- Date::strptime(date, "%d/%m/%Y")
45
- end
46
- end
47
- end
9
+ def add_work_log(date, description)
10
+ WorkLogFileDao.new.save(create_work_log(date, description))
11
+ end
12
+
13
+ def list(date)
14
+ WorkLogFileDao.new.list(parse_date(date))
15
+ end
16
+
17
+ def list_all
18
+ WorkLogFileDao.new.list_all
19
+ end
20
+
21
+ def delete(id)
22
+ WorkLogFileDao.new.delete(id)
23
+ end
24
+
25
+ def find_by_month_and_year(month, year)
26
+ WorkLogFileDao.new.find_by_month_and_year(month, year)
27
+ end
28
+
29
+ def find_by_year(year)
30
+ WorkLogFileDao.new.find_by_year(year)
31
+ end
32
+
33
+ private
34
+
35
+ def create_work_log(date, description)
36
+ WorkLog.new(SecureRandom.uuid, parse_date(date), description)
37
+ end
38
+
39
+ def parse_date(date)
40
+ if date.nil? || date.empty? || date.downcase == 'today'
41
+ Date.today
42
+ elsif date.downcase == 'yesterday'
43
+ Date.today.prev_day
44
+ else
45
+ Date.strptime(date, '%d/%m/%Y')
46
+ end
47
+ end
48
+ end
@@ -1,62 +1,72 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pstore'
2
4
  require 'fileutils'
3
5
 
4
6
  class WorkLogFileDao
5
- DB_FILE_NAME = 'myworklog.pstore'
6
- DB_FOLDER = '.myworklog'
7
- HOME_FOLDER = File.expand_path('~')
8
- FULL_DB_FILE_PATH = "#{HOME_FOLDER}/#{DB_FOLDER}/#{DB_FILE_NAME}"
9
-
10
- def initialize
11
- db_folder_full_path = "#{HOME_FOLDER}/#{DB_FOLDER}"
12
- FileUtils.mkdir_p(db_folder_full_path) unless File.directory?(db_folder_full_path)
13
- end
7
+ DB_FILE_NAME = 'myworklog.pstore'
8
+ DB_FOLDER = '.myworklog'
9
+ HOME_FOLDER = File.expand_path('~')
10
+ FULL_DB_FILE_PATH = "#{HOME_FOLDER}/#{DB_FOLDER}/#{DB_FILE_NAME}"
14
11
 
15
- def save(work_log)
16
- PStore.new(FULL_DB_FILE_PATH).transaction { |store| store[work_log.id] = work_log }
12
+ def initialize
13
+ db_folder_full_path = "#{HOME_FOLDER}/#{DB_FOLDER}"
14
+ unless File.directory?(db_folder_full_path)
15
+ FileUtils.mkdir_p(db_folder_full_path)
17
16
  end
17
+ end
18
18
 
19
- def list(date)
20
- store = PStore.new(FULL_DB_FILE_PATH)
21
- list = []
22
- store.transaction(true) do
23
- store.roots
24
- .map { |root| list << store[root] if store[root].date == date }
25
- end
26
- list
27
- end
19
+ def save(work_log)
20
+ PStore.new(FULL_DB_FILE_PATH).transaction { |store| store[work_log.id] = work_log }
21
+ end
28
22
 
29
- def list_all
30
- store = PStore.new(FULL_DB_FILE_PATH)
31
- list = []
32
- store.transaction(true) { store.roots.map { |root| list << store[root] } }
33
- list
23
+ def list(date)
24
+ store = PStore.new(FULL_DB_FILE_PATH)
25
+ list = []
26
+ store.transaction(true) do
27
+ store.roots
28
+ .map { |root| list << store[root] if store[root].date == date }
34
29
  end
30
+ list
31
+ end
35
32
 
36
- def delete(id)
37
- PStore.new(FULL_DB_FILE_PATH).transaction do |store|
38
- raise Exception.new("Id #{id} not found") if store[id] == nil
39
- store.delete(id)
40
- end
33
+ def list_all
34
+ store = PStore.new(FULL_DB_FILE_PATH)
35
+ list = []
36
+ store.transaction(true) { store.roots.map { |root| list << store[root] } }
37
+ list
38
+ end
39
+
40
+ def delete(id)
41
+ PStore.new(FULL_DB_FILE_PATH).transaction do |store|
42
+ raise Exception, "Id #{id} not found" if store[id].nil?
43
+
44
+ store.delete(id)
41
45
  end
46
+ end
42
47
 
43
- def find_by_month_and_year(month, year)
44
- store = PStore.new(FULL_DB_FILE_PATH)
45
- list = []
46
- store.transaction(true) do
47
- store.roots
48
- .map { |root| list << store[root] if store[root].date.month == month && store[root].date.year == year }
48
+ def find_by_month_and_year(month, year)
49
+ store = PStore.new(FULL_DB_FILE_PATH)
50
+ list = []
51
+ store.transaction(true) do
52
+ store.roots.map do |root|
53
+ if store[root].date.month == month && store[root].date.year == year
54
+ list << store[root]
49
55
  end
50
- list
56
+ end
51
57
  end
58
+ list
59
+ end
52
60
 
53
- def find_by_year(year)
54
- store = PStore.new(FULL_DB_FILE_PATH)
55
- list = []
56
- store.transaction(true) do
57
- store.roots
58
- .map { |root| list << store[root] if store[root].date.year == year }
59
- end
60
- list
61
+ def find_by_year(year)
62
+ store = PStore.new(FULL_DB_FILE_PATH)
63
+ list = []
64
+ store.transaction(true) do
65
+ store.roots
66
+ .map do |root|
67
+ list << store[root] if store[root].date.year == year
68
+ end
61
69
  end
62
- end
70
+ list
71
+ end
72
+ end
data/lib/worklog_cli.rb CHANGED
@@ -1,25 +1,28 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'thor'
2
4
  require 'date'
5
+ require 'rubygems'
3
6
  require_relative 'work_log_controller'
4
7
 
5
8
  DATE_FORMAT = 'DD/MM/YYYY'
6
9
 
7
10
  class WorkLogCli < Thor
8
- desc 'add [DESCRIPTION]', "Adds a new work log with today's date as default. Use -d flag to specify a different date (e.g. myworklog add -d 10/10/2010 'I worked'). Date format #{DATE_FORMAT}"
9
- options :d => :string
10
- def add(description)
11
- begin
12
- date = options[:d] ? options[:d] : 'today'
13
- WorkLogController.new.add_work_log(date, description)
14
- rescue ArgumentError => msg
15
- puts msg
16
- end
17
- end
18
-
19
- desc 'list', "Prints work logs for the current date. Date format #{DATE_FORMAT}"
20
- long_desc <<-LONGDESC
11
+ map %w[--version -v] => :__print_version
12
+
13
+ desc 'add [DESCRIPTION]', "Adds a new work log with today's date as default. Use -d flag to specify a different date (e.g. myworklog add -d 10/10/2010 'I worked'). Date format #{DATE_FORMAT}"
14
+ options d: :string
15
+ def add(description)
16
+ date = options[:d] || 'today'
17
+ WorkLogController.new.add_work_log(date, description)
18
+ rescue ArgumentError => e
19
+ puts e
20
+ end
21
+
22
+ desc 'list', "Prints work logs for the current date. Date format #{DATE_FORMAT}"
23
+ long_desc <<-LONGDESC
21
24
  Prints work logs for the current date if no option specified.
22
-
25
+
23
26
  Availble options:
24
27
 
25
28
  With -m option, prints all the work logs for the specified month, assumes the current year
@@ -36,49 +39,54 @@ class WorkLogCli < Thor
36
39
 
37
40
  `myworklog -y 2020` Will print all the work logs logged in 2020
38
41
 
39
- LONGDESC
40
- options :m => :numeric
41
- options :y => :numeric
42
- def list(date='')
43
- if options[:m] && options[:y]
44
- print(WorkLogController.new.find_by_month_and_year(options[:m], options[:y]))
45
- elsif options[:m] && options[:y] == nil
46
- print(WorkLogController.new.find_by_month_and_year(options[:m], Date.today.year))
47
- elsif options[:m] == nil && options[:y]
48
- print(WorkLogController.new.find_by_year(options[:y]))
49
- else
50
- print(WorkLogController.new.list(date))
51
- end
42
+ LONGDESC
43
+ options m: :numeric
44
+ options y: :numeric
45
+ def list(date = '')
46
+ if options[:m] && options[:y]
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))
52
54
  end
55
+ end
53
56
 
54
- desc 'list_all', "prints all the work logs"
57
+ desc 'list_all', 'prints all the work logs'
55
58
 
56
- def list_all
57
- print(WorkLogController.new.list_all)
58
- end
59
+ def list_all
60
+ print(WorkLogController.new.list_all)
61
+ end
59
62
 
60
- desc 'delete [ID]', 'Deletes the work log by ID. You can use the `list` command to retrieve the ID'
63
+ desc 'delete [ID]', 'Deletes the work log by ID. You can use the `list` command to retrieve the ID'
61
64
 
62
- def delete(id)
63
- begin
64
- WorkLogController.new.delete(id)
65
- puts "Work log with #{id} ID has been deleted!"
66
- rescue Exception => msg
67
- puts msg
68
- end
69
- end
65
+ def delete(id)
66
+ WorkLogController.new.delete(id)
67
+ puts "Work log with #{id} ID has been deleted!"
68
+ rescue Exception => e
69
+ puts e
70
+ end
71
+
72
+ desc '--version -v', 'Prints the current version'
73
+
74
+ def __print_version
75
+ spec = Gem::Specification.load('myworklog.gemspec')
76
+ puts spec.version
77
+ end
78
+
79
+ private
70
80
 
71
- private
72
-
73
- def print(work_log_list)
74
- puts ''
75
- if work_log_list.empty?
76
- puts 'Work log(s) not found'
77
- elsif
78
- work_log_list.each do |work_log|
79
- puts "#{work_log.id} | #{work_log}"
80
- end
81
- end
82
- puts ''
81
+ def print(work_log_list)
82
+ puts ''
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
83
89
  end
84
- end
90
+ puts ''
91
+ end
92
+ end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: myworklog
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
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-20 00:00:00.000000000 Z
11
+ date: 2020-02-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Log your work from cmd and keep track of what you have done. Just in
14
- case your boss asks
13
+ description: Log your work from cmd and keep track of what you have done... just in
14
+ case your boss ask
15
15
  email:
16
16
  - gyowanny@gmail.com
17
17
  executables: