rbnotes 0.4.14 → 0.4.15

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: 21771aaf2f868b68cafa9e3643540a8bae49a96ce3662038c49d3a5053b37b04
4
- data.tar.gz: c91cd115792241d9f441efd93c56305c7b0c97dc02ece0f411ee73277f6bfd82
3
+ metadata.gz: 54f0c34e51ca307615ee9995cf7daeb2f65dff0a3aaa41df305f3414ce6e197e
4
+ data.tar.gz: 48bb529501aabc93ec78dd3fa6d984e11eb4a5dfb8e823d8ea6bdcb80e065e9c
5
5
  SHA512:
6
- metadata.gz: 4bd54a316a4b8461ba93126cffbd2e154fc6231395b8ee7c792c2aeb941cc710ac4f2e4e5b75eb3d902cc5cccb32bd412bfc2b7418b2ab1d9d00173ced928360
7
- data.tar.gz: 1a600b848a559c743789ac1a55f8fcc932da10a063b4d25e31c04d2af94d79c346368271d86a2565fb1d325659c8cf5acbb588a53ac27b227c990d5cce801889
6
+ metadata.gz: b51574083b7d894773b1f597e693209ea6a152533d0035342f4e88f764ac925bf8fe1effd0b81b1a17200d1d5b6e386a0f12c4d790746aae4a6ee7896aa3b990
7
+ data.tar.gz: 59032141edc6f7335d6f6b00c76da7c64f983be04825603b9f3feaa3213e4599b55eff19744df446e5d66b1f8248c523f926a155de3a9d1a5f94a907afea7646
data/CHANGELOG.md CHANGED
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
7
7
  ## [Unreleased]
8
8
  - Nothing to record here.
9
9
 
10
+ ## [0.4.15] - 2021-04-15
11
+ - Enable to use delimiters within a timestamp string. (#104)
12
+ - Fix issue #105: `list` ignores the 2nd arg when specified `-w`
13
+ option.
14
+
10
15
  ## [0.4.14] - 2021-04-10
11
16
  - Add `-n` option to `show` command. (#102)
12
17
  - Fix issue #100: modify to catch Textrepo::MissingTimestampError.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbnotes (0.4.14)
4
+ rbnotes (0.4.15)
5
5
  textrepo (~> 0.5.8)
6
6
  unicode-display_width (~> 1.7)
7
7
 
@@ -34,22 +34,7 @@ module Rbnotes::Commands
34
34
 
35
35
  def execute(args, conf)
36
36
  @opts = {}
37
- while args.size > 0
38
- arg = args.shift
39
- case arg
40
- when "-t", "--timestamp"
41
- stamp_str = args.shift
42
- raise ArgumentError, "missing timestamp: %s" % args.unshift(arg) if stamp_str.nil?
43
- stamp_str = complement_timestamp_pattern(stamp_str)
44
- @opts[:timestamp] = Textrepo::Timestamp.parse_s(stamp_str)
45
- when "-f", "--template-file"
46
- template_path = args.shift
47
- @opts[:template] = template_path
48
- else
49
- args.unshift(arg)
50
- break
51
- end
52
- end
37
+ parse_opts(args)
53
38
 
54
39
  stamp = @opts[:timestamp] || Textrepo::Timestamp.new(Time.now)
55
40
 
@@ -116,7 +101,28 @@ HELP
116
101
  end
117
102
 
118
103
  # :stopdoc:
104
+
119
105
  private
106
+
107
+ def parse_opts(args)
108
+ while args.size > 0
109
+ arg = args.shift
110
+ case arg
111
+ when "-t", "--timestamp"
112
+ stamp_str = args.shift
113
+ raise ArgumentError, "missing timestamp: %s" % args.unshift(arg) if stamp_str.nil?
114
+ stamp_str = complement_timestamp_pattern(stamp_str)
115
+ @opts[:timestamp] = Textrepo::Timestamp.parse_s(stamp_str)
116
+ when "-f", "--template-file"
117
+ template_path = args.shift
118
+ @opts[:template] = template_path
119
+ else
120
+ args.unshift(arg)
121
+ break
122
+ end
123
+ end
124
+ end
125
+
120
126
  def complement_timestamp_pattern(pattern)
121
127
  stamp_str = nil
122
128
  case pattern.to_s.size
@@ -12,18 +12,7 @@ module Rbnotes::Commands
12
12
 
13
13
  def execute(args, conf)
14
14
  @opts = {}
15
- while args.size > 0
16
- arg = args.shift
17
- case arg.to_s
18
- when "" # no options
19
- break
20
- when "-d", "--deve-commands"
21
- @opts[:print_deve_commands] = true
22
- else # invalid options or args
23
- args.unshift(arg)
24
- raise ArgumentError, "invalid option or argument: %s" % args.join(" ")
25
- end
26
- end
15
+ parse_opts(args)
27
16
 
28
17
  puts commands(@opts[:print_deve_commands]).join(" ")
29
18
  end
@@ -42,8 +31,24 @@ HELP
42
31
  end
43
32
 
44
33
  # :stopdoc:
34
+
45
35
  private
46
36
 
37
+ def parse_opts(args)
38
+ while args.size > 0
39
+ arg = args.shift
40
+ case arg.to_s
41
+ when "" # no options
42
+ break
43
+ when "-d", "--deve-commands"
44
+ @opts[:print_deve_commands] = true
45
+ else # invalid options or args
46
+ args.unshift(arg)
47
+ raise ArgumentError, "invalid option or argument: %s" % args.join(" ")
48
+ end
49
+ end
50
+ end
51
+
47
52
  ##
48
53
  # Enumerates all command names.
49
54
  #
@@ -29,16 +29,7 @@ module Rbnotes::Commands
29
29
 
30
30
  def execute(args, conf)
31
31
  @opts = {}
32
- while args.size > 0
33
- arg = args.shift
34
- case arg
35
- when "-m", "--use-mtime"
36
- @opts[:use_mtime] = true
37
- else
38
- args.unshift(arg)
39
- break
40
- end
41
- end
32
+ parse_opts(args)
42
33
 
43
34
  file = args.shift
44
35
  unless file.nil?
@@ -116,5 +107,25 @@ If birthtime is not available on the system, use mtime (modification
116
107
  time).
117
108
  HELP
118
109
  end
110
+
111
+ # :stopdoc:
112
+
113
+ private
114
+
115
+ def parse_opts(args)
116
+ while args.size > 0
117
+ arg = args.shift
118
+ case arg
119
+ when "-m", "--use-mtime"
120
+ @opts[:use_mtime] = true
121
+ else
122
+ args.unshift(arg)
123
+ break
124
+ end
125
+ end
126
+ end
127
+
128
+ # :startdoc:
129
+
119
130
  end
120
131
  end
@@ -54,18 +54,7 @@ module Rbnotes::Commands
54
54
 
55
55
  def execute(args, conf)
56
56
  @opts = {}
57
- while args.size > 0
58
- arg = args.shift
59
- case arg
60
- when "-w", "--week"
61
- @opts[:enum_week] = true
62
- when "-v", "--verbose"
63
- @opts[:verbose] = true
64
- else
65
- args.unshift(arg)
66
- break
67
- end
68
- end
57
+ parse_opts(args)
69
58
 
70
59
  utils = Rbnotes.utils
71
60
  patterns = utils.read_timestamp_patterns(args, enum_week: @opts[:enum_week])
@@ -135,6 +124,21 @@ HELP
135
124
 
136
125
  private
137
126
 
127
+ def parse_opts(args)
128
+ while args.size > 0
129
+ arg = args.shift
130
+ case arg
131
+ when "-w", "--week"
132
+ @opts[:enum_week] = true
133
+ when "-v", "--verbose"
134
+ @opts[:verbose] = true
135
+ else
136
+ args.unshift(arg)
137
+ break
138
+ end
139
+ end
140
+ end
141
+
138
142
  def collect_timestamps_by_date(timestamps)
139
143
  result = {}
140
144
  timestamps.map { |ts|
@@ -11,16 +11,7 @@ module Rbnotes::Commands
11
11
 
12
12
  def execute(args, conf)
13
13
  @opts = {}
14
- while args.size > 0
15
- arg = args.shift
16
- case arg
17
- when "-w", "--week"
18
- @opts[:enum_week] = true
19
- else
20
- args.unshift(arg)
21
- break
22
- end
23
- end
14
+ parse_opts(args)
24
15
 
25
16
  utils = Rbnotes.utils
26
17
  patterns = utils.read_timestamp_patterns(args, enum_week: @opts[:enum_week])
@@ -61,5 +52,25 @@ is specified, it will behave as same as "list" command.
61
52
 
62
53
  HELP
63
54
  end
55
+
56
+ # :stopdoc:
57
+
58
+ private
59
+
60
+ def parse_opts(args)
61
+ while args.size > 0
62
+ arg = args.shift
63
+ case arg
64
+ when "-w", "--week"
65
+ @opts[:enum_week] = true
66
+ else
67
+ args.unshift(arg)
68
+ break
69
+ end
70
+ end
71
+ end
72
+
73
+ # :startdoc:
74
+
64
75
  end
65
76
  end
@@ -9,20 +9,14 @@ module Rbnotes::Commands
9
9
  end
10
10
 
11
11
  def execute(args, conf)
12
+ @opts = {}
13
+ parse_opts(args)
14
+
12
15
  report = :total
13
- while args.size > 0
14
- arg = args.shift
15
- case arg
16
- when "-y", "--yearly"
17
- report = :yearly
18
- break
19
- when "-m", "--monthly"
20
- report = :monthly
21
- break
22
- else
23
- args.unshift(arg)
24
- raise ArgumentError, "invalid option or argument: %s" % args.join(" ")
25
- end
16
+ if @opts[:yearly]
17
+ report = :yearly
18
+ elsif @opts[:monthly]
19
+ report = :monthly
26
20
  end
27
21
 
28
22
  stats = Rbnotes::Statistics.new(conf)
@@ -51,5 +45,30 @@ In the version #{Rbnotes::VERSION}, only number of notes is supported.
51
45
  HELP
52
46
  end
53
47
 
48
+ # :stopdoc:
49
+
50
+ private
51
+
52
+ def parse_opts(args)
53
+ while args.size > 0
54
+ arg = args.shift
55
+ case arg
56
+ when "-y", "--yearly"
57
+ @opts[:yearly] = true
58
+ @opts[:monthly] = false
59
+ break
60
+ when "-m", "--monthly"
61
+ @opts[:yearly] = false
62
+ @opts[:monthly] = true
63
+ break
64
+ else
65
+ args.unshift(arg)
66
+ raise ArgumentError, "invalid option or argument: %s" % args.join(" ")
67
+ end
68
+ end
69
+ end
70
+
71
+ # :startdoc:
72
+
54
73
  end
55
74
  end
@@ -32,16 +32,7 @@ module Rbnotes::Commands
32
32
 
33
33
  def execute(args, conf)
34
34
  @opts = {}
35
- while args.size > 0
36
- arg = args.shift
37
- case arg
38
- when "-k", "--keep"
39
- @opts[:keep_timestamp] = true
40
- else
41
- args.unshift(arg)
42
- break
43
- end
44
- end
35
+ parse_opts(args)
45
36
 
46
37
  target_stamp = Rbnotes.utils.read_timestamp(args)
47
38
  editor = Rbnotes.utils.find_editor(conf[:editor])
@@ -100,5 +91,25 @@ editor program will be searched as same as add command. If none of
100
91
  editors is available, the execution fails.
101
92
  HELP
102
93
  end
94
+
95
+ # :stopdoc:
96
+
97
+ private
98
+
99
+ def parse_opts(args)
100
+ while args.size > 0
101
+ arg = args.shift
102
+ case arg
103
+ when "-k", "--keep"
104
+ @opts[:keep_timestamp] = true
105
+ else
106
+ args.unshift(arg)
107
+ break
108
+ end
109
+ end
110
+ end
111
+
112
+ # :startdoc:
113
+
103
114
  end
104
115
  end
data/lib/rbnotes/utils.rb CHANGED
@@ -103,6 +103,19 @@ module Rbnotes
103
103
  tmpfile
104
104
  end
105
105
 
106
+ # Acceptable delimiters to separate a timestamp string for human
107
+ # being to read and input easily.
108
+ #
109
+ # Here is some examples:
110
+ #
111
+ # - "2021-04-15 15:34:56" -> "20210415153456" (a timestamp string)
112
+ # - "2020-04-15_15:34:56" -> (same as above)
113
+ # - "2020-04-15-15-34-56" -> (same as above)
114
+ # - "2020 04 15 15 34 56" -> (same as above)
115
+ # - "2020-04-15" -> "20200415" (a timestamp pattern)
116
+
117
+ TIMESTAMP_DELIMITERS = /[-:_\s]/
118
+
106
119
  ##
107
120
  # Generates a Textrepo::Timestamp object from a String which comes
108
121
  # from the command line arguments. When no argument is given,
@@ -114,6 +127,8 @@ module Rbnotes
114
127
  def read_timestamp(args)
115
128
  str = args.shift || read_arg($stdin)
116
129
  raise NoArgumentError if str.nil?
130
+
131
+ str = remove_delimiters_from_timestamp_string(str)
117
132
  Textrepo::Timestamp.parse_s(str)
118
133
  end
119
134
 
@@ -135,7 +150,10 @@ module Rbnotes
135
150
  def read_multiple_timestamps(args)
136
151
  strings = args.size < 1 ? read_multiple_args($stdin) : args
137
152
  raise NoArgumentError if (strings.nil? || strings.empty?)
138
- strings.uniq.map { |str| Textrepo::Timestamp.parse_s(str) }
153
+ strings.uniq.map { |str|
154
+ str = remove_delimiters_from_timestamp_string(str)
155
+ Textrepo::Timestamp.parse_s(str)
156
+ }
139
157
  end
140
158
 
141
159
  ##
@@ -147,11 +165,14 @@ module Rbnotes
147
165
  def read_timestamp_patterns(args, enum_week: false)
148
166
  patterns = nil
149
167
  if enum_week
150
- arg = args.shift
151
- begin
152
- patterns = timestamp_patterns_in_week(arg.dup)
153
- rescue InvalidTimestampPatternAsDateError => _e
154
- raise InvalidTimestampPatternAsDateError, args.unshift(arg)
168
+ patterns = []
169
+ while args.size > 0
170
+ arg = args.shift
171
+ begin
172
+ patterns.concat(timestamp_patterns_in_week(arg.dup))
173
+ rescue InvalidTimestampPatternAsDateError => _e
174
+ raise InvalidTimestampPatternAsDateError, args.unshift(arg)
175
+ end
155
176
  end
156
177
  else
157
178
  patterns = expand_keyword_in_args(args)
@@ -174,7 +195,13 @@ module Rbnotes
174
195
  # timestamp_patterns_in_week(String) -> [Array of Strings]
175
196
  #
176
197
  def timestamp_patterns_in_week(arg)
177
- date_str = arg || Textrepo::Timestamp.now[0, 8]
198
+ date_str = nil
199
+
200
+ if arg
201
+ date_str = remove_delimiters_from_timestamp_string(arg)
202
+ else
203
+ date_str = Textrepo::Timestamp.now[0, 8]
204
+ end
178
205
 
179
206
  case date_str.size
180
207
  when "yyyymodd".size
@@ -236,7 +263,7 @@ module Rbnotes
236
263
  patterns << arg
237
264
  end
238
265
  end
239
- patterns.sort.uniq
266
+ patterns.uniq.sort
240
267
  end
241
268
 
242
269
  ##
@@ -322,6 +349,15 @@ module Rbnotes
322
349
  }.compact
323
350
  end
324
351
 
352
+ def remove_delimiters_from_timestamp_string(stamp_str) # :nodoc:
353
+ str = stamp_str.gsub(TIMESTAMP_DELIMITERS, "")
354
+ base_size = "yyyymiddhhmoss".size
355
+ if str.size > base_size # when suffix is specified
356
+ str = str[0...base_size] + "_" + str[base_size..-1]
357
+ end
358
+ str
359
+ end
360
+
325
361
  ##
326
362
  # Expands a keyword to timestamp strings.
327
363
  #
@@ -1,4 +1,4 @@
1
1
  module Rbnotes
2
- VERSION = "0.4.14"
3
- RELEASE = "2021-04-10"
2
+ VERSION = "0.4.15"
3
+ RELEASE = "2021-04-15"
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.14
4
+ version: 0.4.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - mnbi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-09 00:00:00.000000000 Z
11
+ date: 2021-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: textrepo