rbnotes 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f48ac5666d917964e9c103c11be86b12736b81ced6e072be4707e1e943b6ff76
4
- data.tar.gz: d29b9b68d6ebfcfdc7289962405a0390daed2705cd80b3beb50e036d2f8d9e85
3
+ metadata.gz: a04bd4d45d7c2f4227f355672baa860602ae3b9e481e7a384daf4283f4ad6754
4
+ data.tar.gz: bc707b20ea91ab655f6e355026164c01844c82ea3869c18fd5ca1040c968934d
5
5
  SHA512:
6
- metadata.gz: f5be0687fc189a5dad6178104a05af0f64e35fc44dd1a73bf677a232038b81b4f88e5562ca9f9e8f098152136c005ebdc334158d34652c0fe7a2bea8e13c4056
7
- data.tar.gz: a1e5d671d93ff9efdbe33e7c6751984f851c39756304df7c874fe82df558b18b7f4f716d82253e99b2d8e21cc1d795d6b81c0f1ba665f8f3e99e38c30e4d19d8
6
+ metadata.gz: d93df0df9e002a8bae26b7d9e1e89acf19d84551635d58f3ec747c78f3764ac004a784977a3d9940783a8b4661b2caafd2b55502644bca4bb69947d91593bd79
7
+ data.tar.gz: 913c240b04215cb5502146f4d1edcd5c1ddc273de31baace3f0d8dff600dcf759e5983aee5cce72fb5079dc26e1a22b43c0aad46e1cc766c4127697090fb0037
@@ -7,9 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
7
7
  ## [Unreleased]
8
8
  Nothing to record here.
9
9
 
10
+ ## [0.4.4] - 2020-11-09
11
+ ###
12
+ - Add a feature to use a keyword as an argument for `list`. (#47)
13
+
10
14
  ## [0.4.3] - 2020-11-08
11
15
  ### Added
12
- - Add a new command `export` to write out a note into a file (#51)
16
+ - Add a new command `export` to write out a note into a file. (#51)
13
17
  - Add individual help for each command. (#42)
14
18
 
15
19
  ### Fixed
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbnotes (0.4.3)
4
+ rbnotes (0.4.4)
5
5
  textrepo (~> 0.5.4)
6
6
  unicode-display_width (~> 1.7)
7
7
 
@@ -61,7 +61,7 @@ Example usage:
61
61
  #{Rbnotes::NAME} delete [TIMESTAMP]
62
62
  #{Rbnotes::NAME} export [TIMESTAMP [FILENAME]]
63
63
  #{Rbnotes::NAME} import FILE
64
- #{Rbnotes::NAME} list [STAMP_PATTERN]
64
+ #{Rbnotes::NAME} list [STAMP_PATTERN|KEYWORD]
65
65
  #{Rbnotes::NAME} search PATTERN [STAMP_PATTERN]
66
66
  #{Rbnotes::NAME} show [TIMESTAMP]
67
67
  #{Rbnotes::NAME} update [TIMESTAMP]
@@ -1,3 +1,4 @@
1
+ require "date"
1
2
  require "unicode/display_width"
2
3
  require "io/console/size"
3
4
 
@@ -20,8 +21,7 @@ module Rbnotes::Commands
20
21
  # timestamp pattern is a string which would match several
21
22
  # Timestamp objects.
22
23
  #
23
- # Here is
24
- # several examples of timestamp patterns.
24
+ # Here is several examples of timestamp patterns.
25
25
  #
26
26
  # "20201027093600_012": a complete string to represent a timestamp
27
27
  # - this pattern would match exactly one Timestamp object
@@ -43,11 +43,28 @@ module Rbnotes::Commands
43
43
  # execute(Array, Rbnotes::Conf or Hash) -> nil
44
44
 
45
45
  def execute(args, conf)
46
- pattern = args.shift # `nil` is acceptable
46
+ arg = args.shift
47
+ patterns = []
48
+
49
+ case arg.to_s
50
+ when "today", "to"
51
+ patterns << Textrepo::Timestamp.new(Time.now).to_s[0..7]
52
+ when "yesterday", "ye"
53
+ t = Time.now
54
+ patterns << Date.new(t.year, t.mon, t.day).prev_day.strftime("%Y%m%d")
55
+ when "this_week", "tw"
56
+ patterns.concat(dates_in_this_week)
57
+ when "last_week", "lw"
58
+ patterns.concat(dates_in_last_week)
59
+ else
60
+ patterns << arg
61
+ end
47
62
 
48
63
  @repo = Textrepo.init(conf)
64
+ stamps = patterns.map { |pat|
65
+ @repo.entries(pat).sort{|a, b| b <=> a}
66
+ }.flatten
49
67
  # newer stamp shoud be above
50
- stamps = @repo.entries(pattern).sort{|a, b| b <=> a}
51
68
  stamps.each { |timestamp|
52
69
  puts make_headline(timestamp)
53
70
  }
@@ -56,11 +73,12 @@ module Rbnotes::Commands
56
73
  def help # :nodoc:
57
74
  puts <<HELP
58
75
  usage:
59
- #{Rbnotes::NAME} list [STAMP_PATTERN]
76
+ #{Rbnotes::NAME} list [STAMP_PATTERN|KEYWORD]
60
77
 
61
78
  Show a list of notes. When no arguments, make a list with all notes
62
79
  in the repository. When specified STAMP_PATTERN, only those match the
63
- pattern are listed.
80
+ pattern are listed. Instead of STAMP_PATTERN, some KEYWORDs could be
81
+ used.
64
82
 
65
83
  STAMP_PATTERN must be:
66
84
 
@@ -69,6 +87,14 @@ STAMP_PATTERN must be:
69
87
  (c) year and month part: "202010"
70
88
  (d) year part only: "2020"
71
89
  (e) date part only: "1030"
90
+
91
+ KEYWORD:
92
+
93
+ - "today" (or "to")
94
+ - "yeasterday" (or "ye")
95
+ - "this_week" (or "tw")
96
+ - "last_week" (or "lw")
97
+
72
98
  HELP
73
99
  end
74
100
 
@@ -119,6 +145,29 @@ HELP
119
145
  str.sub(/^#+ +/, '')
120
146
  end
121
147
 
148
+ # week day for Monday start calendar
149
+ def wday(time)
150
+ (time.wday - 1) % 7
151
+ end
152
+
153
+ def dates_in_this_week
154
+ to = Time.now
155
+ start = Date.new(to.year, to.mon, to.day).prev_day(wday(to))
156
+ dates_in_week(start)
157
+ end
158
+
159
+ def dates_in_last_week
160
+ to = Time.now
161
+ start_of_this_week = Date.new(to.year, to.mon, to.day).prev_day(wday(to))
162
+ dates_in_week(start_of_this_week.prev_day(7))
163
+ end
164
+
165
+ def dates_in_week(start_date)
166
+ dates = [start_date]
167
+ 1.upto(6) { |i| dates << start_date.next_day(i) }
168
+ dates.map { |d| d.strftime("%Y%m%d") }
169
+ end
170
+
122
171
  # :startdoc:
123
172
  end
124
173
  end
@@ -1,4 +1,4 @@
1
1
  module Rbnotes
2
- VERSION = "0.4.3"
3
- RELEASE = "2020-11-08"
2
+ VERSION = "0.4.4"
3
+ RELEASE = "2020-11-09"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbnotes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - mnbi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-08 00:00:00.000000000 Z
11
+ date: 2020-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: textrepo