rbnotes 0.4.8 → 0.4.9

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: de852db7e0679690dc371c256eb8f65a5f8022772b04ed6024c4f4b55c5cebae
4
- data.tar.gz: 27764e6f940f29be341745d50db658ef419af0e576b674533398910694f294f7
3
+ metadata.gz: 4e4e20e7274cc9e4f9d013340447f7fb06a7dcf45d8536d71e6c6f456a29d310
4
+ data.tar.gz: e41d785998768d9b4655575ae5303240de437243b6349ecd4ce147a5a051359b
5
5
  SHA512:
6
- metadata.gz: de49f9046ad826a346cabd37bab304e1d0ab08dfda4e6f5ca6ce7b216cc717ed39645baf092aa993e8287bd65761a605d1f2d1c158e465bc75efbac68ceeb785
7
- data.tar.gz: 9c28c82c7b486695a5e5fe5875fda39e69bc1673e85434368fba4a2a1a71c0cff1918e60c88ecfd43bf22546bbb79d121319044b1fb068da5445dbc78b239639
6
+ metadata.gz: 5b2f313ceab8c9a18205189235d72f13c48b7724ba8b15e2651bfb79e1af62e55e1fc1d855eaa0b6eadb3b715e3fd85bd70fe692bbf18d706191a81532a27b0d
7
+ data.tar.gz: 430276b6461f3502e8f74463451c67a4ddfe40fe7abd5a676abbb6f0ac24980890de6f6ac22f5a7dd64827283c7b101323d4c21b6b210e8c99a577823244885f
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
7
7
  ## [Unreleased]
8
8
  Nothing to record here.
9
9
 
10
+ ## [0.4.9] - 2020-11-17
11
+ ### Added
12
+ - Add a new option `--week` to the `list` command. (#67)
13
+
10
14
  ## [0.4.8] - 2020-11-16
11
15
  ### Fixed
12
16
  - Fix issue #65: messy output of the `search` command.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbnotes (0.4.8)
4
+ rbnotes (0.4.9)
5
5
  textrepo (~> 0.5.4)
6
6
  unicode-display_width (~> 1.7)
7
7
 
@@ -51,7 +51,34 @@ module Rbnotes::Commands
51
51
  # execute(Array, Rbnotes::Conf or Hash) -> nil
52
52
 
53
53
  def execute(args, conf)
54
- patterns = Rbnotes.utils.expand_keyword_in_args(args)
54
+ @opts = {}
55
+ while args.size > 0
56
+ arg = args.shift
57
+ case arg
58
+ when "-w", "--week"
59
+ @opts[:enum_week] = true
60
+ else
61
+ args.unshift(arg)
62
+ break
63
+ end
64
+ end
65
+
66
+ patterns = nil
67
+ if @opts[:enum_week]
68
+ arg = args.shift || Textrepo::Timestamp.now[0, 8]
69
+ case arg.size
70
+ when "yyyymodd".size, "yyyymoddhhmiss".size, "yyyymoddhhmiss_sfx".size
71
+ stamp_str = "#{arg}000000"[0, 14]
72
+ timestamp = Textrepo::Timestamp.parse_s(stamp_str)
73
+ patterns = Rbnotes.utils.timestamp_patterns_in_week(timestamp)
74
+ else
75
+ raise InvalidTimestampPatternError,
76
+ "cannot convert to a date [%s]" % args.unshift(arg)
77
+ end
78
+ else
79
+ patterns = Rbnotes.utils.expand_keyword_in_args(args)
80
+ end
81
+
55
82
  @repo = Textrepo.init(conf)
56
83
  # newer stamp shoud be above
57
84
  Rbnotes.utils.find_notes(patterns, @repo).each { |timestamp|
@@ -62,7 +89,7 @@ module Rbnotes::Commands
62
89
  def help # :nodoc:
63
90
  puts <<HELP
64
91
  usage:
65
- #{Rbnotes::NAME} list [STAMP_PATTERN|KEYWORD]
92
+ #{Rbnotes::NAME} list [-w|--week][STAMP_PATTERN|KEYWORD]
66
93
 
67
94
  Show a list of notes. When no arguments, make a list with all notes
68
95
  in the repository. When specified STAMP_PATTERN, only those match the
@@ -84,6 +111,16 @@ KEYWORD:
84
111
  - "this_week" (or "tw")
85
112
  - "last_week" (or "lw")
86
113
 
114
+ An option "--week" is also acceptable. It specifies to enumerate all
115
+ days of a week. Typically, the option is used with a STAMP_PATTERN
116
+ which specifies a date, such "20201117", then it enumerates all days
117
+ of the week which contains "17th November 2020".
118
+
119
+ A STAMP_PATTERN other than (a) and (b) causes an error if it was used
120
+ with "--week" option.
121
+
122
+ When no STAMP_PATTERN was specified with "--week" option, the output
123
+ would be as same as the KEYWORD, "this_week" was specified.
87
124
  HELP
88
125
  end
89
126
 
@@ -7,11 +7,12 @@ module Rbnotes
7
7
  # :stopdoc:
8
8
 
9
9
  module ErrMsg
10
- MISSING_ARGUMENT = "missing argument: %s"
11
- MISSING_TIMESTAMP = "missing timestamp: %s"
10
+ MISSING_ARGUMENT = "Missing argument: %s"
11
+ MISSING_TIMESTAMP = "Missing timestamp: %s"
12
12
  NO_EDITOR = "No editor is available: %s"
13
13
  PROGRAM_ABORT = "External program was aborted: %s"
14
14
  UNKNOWN_KEYWORD = "Unknown keyword: %s"
15
+ INVALID_TIMESTAMP_PATTERN = "Invalid timestamp pattern: %s"
15
16
  end
16
17
 
17
18
  # :startdoc:
@@ -64,4 +65,14 @@ module Rbnotes
64
65
  super(ErrMsg::UNKNOWN_KEYWORD % keyword)
65
66
  end
66
67
  end
68
+
69
+ ##
70
+ # An error raised when an invalid timestamp pattern was specified.
71
+
72
+ class InvalidTimestampPatternError < Error
73
+ def initialize(pattern)
74
+ super(ErrMsg::INVALID_TIMESTAMP_PATTERN % pattern)
75
+ end
76
+ end
77
+
67
78
  end
@@ -227,6 +227,17 @@ module Rbnotes
227
227
  }.flatten.sort{ |a, b| b <=> a }.uniq
228
228
  end
229
229
 
230
+ ##
231
+ # Enumerates all timestamp patterns in a week which contains a
232
+ # given timestamp as a day of the week.
233
+ #
234
+ # :call-seq:
235
+ # timestamp_patterns_in_week(timestamp) -> [Array of Strings]
236
+
237
+ def timestamp_patterns_in_week(timestamp)
238
+ dates_in_week(start_date_in_the_week(timestamp.time)).map { |date| timestamp_pattern(date) }
239
+ end
240
+
230
241
  # :stopdoc:
231
242
 
232
243
  private
@@ -268,14 +279,18 @@ module Rbnotes
268
279
  end
269
280
 
270
281
  def start_date_in_this_week
271
- today = Time.now
272
- Date.new(today.year, today.mon, today.day).prev_day(wday(today))
282
+ start_date_in_the_week(Time.now)
273
283
  end
274
284
 
275
285
  def start_date_in_last_week
276
286
  start_date_in_this_week.prev_day(7)
277
287
  end
278
288
 
289
+ def start_date_in_the_week(time)
290
+ parts = [:year, :mon, :day].map { |sym| time.send(sym) }
291
+ Date.new(*parts).prev_day(wday(time))
292
+ end
293
+
279
294
  def wday(time)
280
295
  (time.wday - 1) % 7
281
296
  end
@@ -1,4 +1,4 @@
1
1
  module Rbnotes
2
- VERSION = "0.4.8"
3
- RELEASE = "2020-11-16"
2
+ VERSION = "0.4.9"
3
+ RELEASE = "2020-11-17"
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.8
4
+ version: 0.4.9
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-16 00:00:00.000000000 Z
11
+ date: 2020-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: textrepo