rbnotes 0.4.12 → 0.4.13

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: 517b5866c81f76286f87b2ed7d2e695c4dd09d5c7ab86f9557079232a58fde37
4
- data.tar.gz: 1d89412445d155501f67cd0978a8070975ed722ee7440119cf5a9ba89ca946eb
3
+ metadata.gz: 55b7ddb12d306be2cb815400d4e729deff8badfbde55ede0f9edba78c380eb44
4
+ data.tar.gz: ae0720108810db518693959f3a8faf20c7ca985d6aaf3c39bac94327d45f25db
5
5
  SHA512:
6
- metadata.gz: 1f0bab361e6f4a7f22a59433369b221b6dffc1e16b79f9d4bdc4027d78c3d61a6e949ab2b81ae1ab3be4c5d52af6bd74aed4b36c70a93f31e710a42b7bb23731
7
- data.tar.gz: af38ba13276090ae653fee8b1b3f67f3de57596851ce8b645f4ed3463c38d71c4a950b3382bff55ad98853c42e2cb3f2df0e7e7652f756f385d53ef15f917085
6
+ metadata.gz: 8fc47bdc0c93bc964714c89d791655f1d385de0dfbf6af5202ec18c17f1be951efb02fcd4d9b0ac9b298cbb163e8a9e836a5c4d752bf9bad5299cc0d38983463
7
+ data.tar.gz: d2a3db96531609429775b9caf32308691afc6023ffaf2d8aae39df3d763e99b497a3efe763e821033ab725240e925ddd23a5385dac15d0a3bd5f3cb9f7c23ac1
@@ -0,0 +1,18 @@
1
+ name: Build
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 3.0.0
14
+ - name: Run the default task
15
+ run: |
16
+ gem install bundler -v 2.2.3
17
+ bundle install
18
+ bundle exec rake
data/.gitignore CHANGED
@@ -35,7 +35,6 @@ build-iPhoneSimulator/
35
35
  ## Documentation cache and generated files:
36
36
  /.yardoc/
37
37
  /_yardoc/
38
- /doc/
39
38
  /rdoc/
40
39
 
41
40
  ## Environment normalization:
data/CHANGELOG.md CHANGED
@@ -5,7 +5,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/)
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/).
6
6
 
7
7
  ## [Unreleased]
8
- Nothing to record here.
8
+
9
+ ## [0.4.13] - 2021-03-30
10
+ ### Changed
11
+ - Use GitHub/Actions instead of Travis-CI.
12
+ - Add `--week` option to `pick` command. (#88)
13
+
14
+ ### Fixed
15
+ - Fix issue #98: remove redundant args
16
+ (Rbnotes::Utils.read_multiple_timestamps). (#98)
17
+ - Update `textrepo`. -> 0.5.8 (#97)
9
18
 
10
19
  ## [0.4.12] - 2020-12-18
11
20
  ### Changed
data/Gemfile CHANGED
@@ -6,4 +6,4 @@ gemspec
6
6
  gem "rake", "~> 13.0"
7
7
  gem "minitest", "~> 5.0"
8
8
 
9
- gem 'textrepo', "~> 0.5.4"
9
+ gem 'textrepo', "~> 0.5.8"
data/Gemfile.lock CHANGED
@@ -1,16 +1,16 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbnotes (0.4.12)
5
- textrepo (~> 0.5.4)
4
+ rbnotes (0.4.13)
5
+ textrepo (~> 0.5.8)
6
6
  unicode-display_width (~> 1.7)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- minitest (5.14.2)
12
- rake (13.0.1)
13
- textrepo (0.5.7)
11
+ minitest (5.14.4)
12
+ rake (13.0.3)
13
+ textrepo (0.5.8)
14
14
  unicode-display_width (1.7.0)
15
15
 
16
16
  PLATFORMS
@@ -20,7 +20,7 @@ DEPENDENCIES
20
20
  minitest (~> 5.0)
21
21
  rake (~> 13.0)
22
22
  rbnotes!
23
- textrepo (~> 0.5.4)
23
+ textrepo (~> 0.5.8)
24
24
 
25
25
  BUNDLED WITH
26
- 2.1.4
26
+ 2.2.3
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Rbnotes
2
2
 
3
- [![Build Status](https://travis-ci.org/mnbi/rbnotes.svg?branch=main)](https://travis-ci.org/mnbi/rbnotes)
3
+ [![Build Status](https://github.com/mnbi/rbnotes/workflows/Build/badge.svg)](https://github.com/mnbi/rbnotes/actions?query=workflow%3A"Build")
4
4
 
5
5
  Rbnotes is a simple utility to write a note in the single repository.
6
6
 
data/Rakefile CHANGED
@@ -25,6 +25,6 @@ require "rdoc/task"
25
25
 
26
26
  RDoc::Task.new do |rdoc|
27
27
  rdoc.generator = "ri"
28
- rdoc.rdoc_dir = "doc"
28
+ rdoc.rdoc_dir = "rdoc"
29
29
  rdoc.rdoc_files.include("lib/**/*.rb")
30
30
  end
data/lib/rbnotes.rb CHANGED
@@ -10,9 +10,4 @@ module Rbnotes
10
10
  require_relative "rbnotes/commands"
11
11
  require_relative "rbnotes/statistics"
12
12
 
13
- class << self
14
- def utils
15
- Utils.instance
16
- end
17
- end
18
13
  end
@@ -67,44 +67,24 @@ module Rbnotes::Commands
67
67
  end
68
68
  end
69
69
 
70
- patterns = nil
71
- if @opts[:enum_week]
72
- arg = args.shift || Textrepo::Timestamp.now[0, 8]
73
- case arg.size
74
- when "yyyymodd".size, "yyyymoddhhmiss".size, "yyyymoddhhmiss_sfx".size
75
- stamp_str = "#{arg}000000"[0, 14]
76
- timestamp = Textrepo::Timestamp.parse_s(stamp_str)
77
- when "modd".size
78
- this_year = Time.now.year.to_s
79
- stamp_str = "#{this_year}#{arg}000000"
80
- begin
81
- timestamp = Textrepo::Timestamp.parse_s(stamp_str)
82
- rescue Textrepo::InvalidTimestampStringError => _e
83
- raise InvalidTimestampPatternAsDateError, arg
84
- end
85
- else
86
- raise InvalidTimestampPatternAsDateError, args.unshift(arg)
87
- end
88
- patterns = Rbnotes.utils.timestamp_patterns_in_week(timestamp)
89
- else
90
- patterns = Rbnotes.utils.expand_keyword_in_args(args)
91
- end
70
+ utils = Rbnotes.utils
71
+ patterns = utils.read_timestamp_patterns(args, enum_week: @opts[:enum_week])
92
72
 
93
73
  @repo = Textrepo.init(conf)
94
- notes = Rbnotes.utils.find_notes(patterns, @repo)
74
+ notes = utils.find_notes(patterns, @repo)
95
75
  output = []
96
76
  if @opts[:verbose]
97
77
  collect_timestamps_by_date(notes).each { |date, timestamps|
98
78
  output << "#{date} (#{timestamps.size})"
99
79
  timestamps.each { |timestamp|
100
80
  pad = " "
101
- output << Rbnotes.utils.make_headline(timestamp,
81
+ output << utils.make_headline(timestamp,
102
82
  @repo.read(timestamp), pad)
103
83
  }
104
84
  }
105
85
  else
106
86
  notes.each { |timestamp|
107
- output << Rbnotes.utils.make_headline(timestamp,
87
+ output << utils.make_headline(timestamp,
108
88
  @repo.read(timestamp))
109
89
  }
110
90
  end
@@ -10,12 +10,26 @@ module Rbnotes::Commands
10
10
  end
11
11
 
12
12
  def execute(args, conf)
13
- patterns = Rbnotes.utils.expand_keyword_in_args(args)
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
24
+
25
+ utils = Rbnotes.utils
26
+ patterns = utils.read_timestamp_patterns(args, enum_week: @opts[:enum_week])
27
+
14
28
  @repo = Textrepo.init(conf)
15
29
 
16
30
  list = []
17
- Rbnotes.utils.find_notes(patterns, @repo).each { |timestamp|
18
- list << Rbnotes.utils.make_headline(timestamp, @repo.read(timestamp))
31
+ utils.find_notes(patterns, @repo).each { |timestamp|
32
+ list << utils.make_headline(timestamp, @repo.read(timestamp))
19
33
  }
20
34
 
21
35
  picker = conf[:picker]
data/lib/rbnotes/utils.rb CHANGED
@@ -7,6 +7,20 @@ require "io/console/size"
7
7
  require "unicode/display_width"
8
8
 
9
9
  module Rbnotes
10
+
11
+ class << self
12
+
13
+ ##
14
+ # Retrieves the singleton instance of Rbnotes::Utils class.
15
+ # Typical usage is as follows:
16
+ #
17
+ # Rbnotes.utils.find_editor("emacsclient")
18
+ #
19
+ def utils
20
+ Utils.instance
21
+ end
22
+ end
23
+
10
24
  ##
11
25
  # Defines several utility methods those are intended to be used in
12
26
  # Rbnotes classes.
@@ -108,13 +122,79 @@ module Rbnotes
108
122
  # line arguments. When no argument is given, try to read from
109
123
  # STDIN.
110
124
  #
125
+ # When multiple strings those point the identical time are
126
+ # included the arguments (passed or read form STDIN), the
127
+ # redundant strings will be removed.
128
+ #
129
+ # The order of the arguments will be preserved into the return
130
+ # value, even if the redundant strings were removed.
131
+ #
111
132
  # :call-seq:
112
133
  # read_multiple_timestamps(args) -> [String]
113
134
 
114
135
  def read_multiple_timestamps(args)
115
136
  strings = args.size < 1 ? read_multiple_args($stdin) : args
116
137
  raise NoArgumentError if (strings.nil? || strings.empty?)
117
- strings.map { |str| Textrepo::Timestamp.parse_s(str) }
138
+ strings.uniq.map { |str| Textrepo::Timestamp.parse_s(str) }
139
+ end
140
+
141
+ ##
142
+ # Reads timestamp patterns in an array of arguments. It supports
143
+ # keywords expansion and enumeration of week. The function is
144
+ # intended to be used from Commands::List#execute and
145
+ # Commands::Pick#execute.
146
+ #
147
+ def read_timestamp_patterns(args, enum_week: false)
148
+ patterns = nil
149
+ 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)
155
+ end
156
+ else
157
+ patterns = expand_keyword_in_args(args)
158
+ end
159
+ patterns
160
+ end
161
+
162
+ ##
163
+ # Enumerates all timestamp patterns in a week which contains a
164
+ # given timestamp as a day of the week.
165
+ #
166
+ # The argument must be one of the followings:
167
+ # - "yyyymodd" (eg. "20201220")
168
+ # - "yymoddhhmiss" (eg. "20201220120048")
169
+ # - "yymoddhhmiss_sfx" (eg. "20201220120048_012")
170
+ # - "modd" (eg. "1220") (assums in the current year)
171
+ # - nil (assumes today)
172
+ #
173
+ # :call-seq:
174
+ # timestamp_patterns_in_week(String) -> [Array of Strings]
175
+ #
176
+ def timestamp_patterns_in_week(arg)
177
+ date_str = arg || Textrepo::Timestamp.now[0, 8]
178
+
179
+ case date_str.size
180
+ when "yyyymodd".size
181
+ # nothing to do
182
+ when "yyyymoddhhmiss".size, "yyyymoddhhmiss_sfx".size
183
+ date_str = date_str[0, 8]
184
+ when "modd".size
185
+ this_year = Time.now.year.to_s
186
+ date_str = "#{this_year}#{date_str}"
187
+ else
188
+ raise InvalidTimestampPatternAsDateError, arg
189
+ end
190
+
191
+ begin
192
+ date = Date.parse(date_str)
193
+ rescue Date::Error => _e
194
+ raise InvalidTimestampPatternAsDateError, arg
195
+ end
196
+
197
+ dates_in_week(date).map { |date| timestamp_pattern(date) }
118
198
  end
119
199
 
120
200
  ##
@@ -143,17 +223,15 @@ module Rbnotes
143
223
  #
144
224
  # :call-seq:
145
225
  # expand_keyword_in_args(Array of Strings) -> Array of Strings
146
-
226
+ #
147
227
  def expand_keyword_in_args(args)
148
228
  return [nil] if args.empty?
149
229
 
150
230
  patterns = []
151
231
  while args.size > 0
152
232
  arg = args.shift
153
- if ["today", "to", "yesterday", "ye",
154
- "this_week", "tw", "last_week", "lw",
155
- "this_month", "tm", "last_month", "lm"].include?(arg)
156
- patterns.concat(Rbnotes.utils.expand_keyword(arg))
233
+ if KEYWORDS.include?(arg)
234
+ patterns.concat(expand_keyword(arg))
157
235
  else
158
236
  patterns << arg
159
237
  end
@@ -161,33 +239,6 @@ module Rbnotes
161
239
  patterns.sort.uniq
162
240
  end
163
241
 
164
- ##
165
- # Expands a keyword to timestamp strings.
166
- #
167
- # :call-seq:
168
- # expand_keyword(keyword as String) -> Array of timestamp Strings
169
-
170
- def expand_keyword(keyword)
171
- patterns = []
172
- case keyword
173
- when "today", "to"
174
- patterns << timestamp_pattern(date_of_today)
175
- when "yesterday", "ye"
176
- patterns << timestamp_pattern(date_of_yesterday)
177
- when "this_week", "tw"
178
- patterns.concat(dates_in_this_week.map { |d| timestamp_pattern(d) })
179
- when "last_week", "lw"
180
- patterns.concat(dates_in_last_week.map { |d| timestamp_pattern(d) })
181
- when "this_month", "tm"
182
- patterns.concat(dates_in_this_month.map { |d| timestamp_pattern(d) })
183
- when "last_month", "lm"
184
- patterns.concat(dates_in_last_month.map { |d| timestamp_pattern(d) })
185
- else
186
- raise UnknownKeywordError, keyword
187
- end
188
- patterns
189
- end
190
-
191
242
  ##
192
243
  # Makes a headline with the timestamp and subject of the notes, it
193
244
  # looks like as follows:
@@ -233,17 +284,6 @@ module Rbnotes
233
284
  }.flatten.sort{ |a, b| b <=> a }.uniq
234
285
  end
235
286
 
236
- ##
237
- # Enumerates all timestamp patterns in a week which contains a
238
- # given timestamp as a day of the week.
239
- #
240
- # :call-seq:
241
- # timestamp_patterns_in_week(timestamp) -> [Array of Strings]
242
-
243
- def timestamp_patterns_in_week(timestamp)
244
- dates_in_week(start_date_in_the_week(timestamp.time)).map { |date| timestamp_pattern(date) }
245
- end
246
-
247
287
  # :stopdoc:
248
288
 
249
289
  private
@@ -282,6 +322,39 @@ module Rbnotes
282
322
  }.compact
283
323
  end
284
324
 
325
+ ##
326
+ # Expands a keyword to timestamp strings.
327
+ #
328
+ # :call-seq:
329
+ # expand_keyword(keyword as String) -> Array of timestamp Strings
330
+ #
331
+ def expand_keyword(keyword)
332
+ patterns = []
333
+ case keyword
334
+ when "today", "to"
335
+ patterns << timestamp_pattern(Date.today)
336
+ when "yesterday", "ye"
337
+ patterns << timestamp_pattern(Date.today.prev_day)
338
+ when "this_week", "tw"
339
+ patterns.concat(dates_in_this_week.map { |d| timestamp_pattern(d) })
340
+ when "last_week", "lw"
341
+ patterns.concat(dates_in_last_week.map { |d| timestamp_pattern(d) })
342
+ when "this_month", "tm"
343
+ patterns.concat(dates_in_this_month.map { |d| timestamp_pattern(d) })
344
+ when "last_month", "lm"
345
+ patterns.concat(dates_in_last_month.map { |d| timestamp_pattern(d) })
346
+ else
347
+ raise UnknownKeywordError, keyword
348
+ end
349
+ patterns
350
+ end
351
+
352
+ KEYWORDS = %w(
353
+ today to yesterday ye
354
+ this_week tw last_week lw
355
+ this_month tm last_month lm
356
+ )
357
+
285
358
  def search_in_path(name)
286
359
  search_paths = ENV["PATH"].split(":")
287
360
  found = search_paths.map { |path|
@@ -299,58 +372,40 @@ module Rbnotes
299
372
  date.strftime("%Y%m%d")
300
373
  end
301
374
 
302
- def date_of_today
303
- date(Time.now)
304
- end
305
-
306
- def date_of_yesterday
307
- date(Time.now).prev_day
308
- end
309
-
310
375
  def date(time)
311
376
  Date.new(time.year, time.mon, time.day)
312
377
  end
313
378
 
314
379
  def dates_in_this_week
315
- dates_in_week(start_date_in_this_week)
380
+ dates_in_week(Date.today)
316
381
  end
317
382
 
318
383
  def dates_in_last_week
319
- dates_in_week(start_date_in_last_week)
320
- end
321
-
322
- def start_date_in_this_week
323
- start_date_in_the_week(Time.now)
384
+ dates_in_week(Date.today.prev_day(7))
324
385
  end
325
386
 
326
- def start_date_in_last_week
327
- start_date_in_this_week.prev_day(7)
328
- end
329
-
330
- def start_date_in_the_week(time)
331
- parts = [:year, :mon, :day].map { |sym| time.send(sym) }
332
- Date.new(*parts).prev_day(wday(time))
387
+ def dates_in_week(date)
388
+ start_date = start_date_of_week(date)
389
+ dates = [start_date]
390
+ 1.upto(6) { |i| dates << start_date.next_day(i) }
391
+ dates
333
392
  end
334
393
 
335
- def wday(time)
336
- (time.wday - 1) % 7
394
+ def start_date_of_week(date)
395
+ # week day in monday start calendar
396
+ date.prev_day((date.wday - 1) % 7)
337
397
  end
338
398
 
339
- def dates_in_week(start_date)
340
- dates = [start_date]
341
- 1.upto(6) { |i| dates << start_date.next_day(i) }
342
- dates
399
+ def first_date_of_this_month
400
+ today = Time.now
401
+ date(Time.new(today.year, today.mon, 1))
343
402
  end
344
403
 
345
404
  def dates_in_this_month
346
- today = Time.now
347
- first_date = date(Time.new(today.year, today.mon, 1))
348
- dates_in_month(first_date)
405
+ dates_in_month(first_date_of_this_month)
349
406
  end
350
407
 
351
408
  def dates_in_last_month
352
- today = Time.now
353
- first_date_of_this_month = date(Time.new(today.year, today.mon, 1))
354
409
  dates_in_month(first_date_of_this_month.prev_month)
355
410
  end
356
411
 
@@ -1,4 +1,4 @@
1
1
  module Rbnotes
2
- VERSION = "0.4.12"
3
- RELEASE = "2020-12-18"
2
+ VERSION = "0.4.13"
3
+ RELEASE = "2021-03-30"
4
4
  end
data/rbnotes.gemspec CHANGED
@@ -25,6 +25,6 @@ Gem::Specification.new do |spec|
25
25
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
26
  spec.require_paths = ["lib"]
27
27
 
28
- spec.add_dependency "textrepo", "~> 0.5.4"
28
+ spec.add_dependency "textrepo", "~> 0.5.8"
29
29
  spec.add_dependency "unicode-display_width", "~> 1.7"
30
30
  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.12
4
+ version: 0.4.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - mnbi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-12-18 00:00:00.000000000 Z
11
+ date: 2021-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: textrepo
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.5.4
19
+ version: 0.5.8
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.5.4
26
+ version: 0.5.8
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: unicode-display_width
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -46,8 +46,8 @@ executables:
46
46
  extensions: []
47
47
  extra_rdoc_files: []
48
48
  files:
49
+ - ".github/workflows/main.yml"
49
50
  - ".gitignore"
50
- - ".travis.yml"
51
51
  - CHANGELOG.md
52
52
  - Gemfile
53
53
  - Gemfile.lock
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  - !ruby/object:Gem::Version
107
107
  version: '0'
108
108
  requirements: []
109
- rubygems_version: 3.1.4
109
+ rubygems_version: 3.2.3
110
110
  signing_key:
111
111
  specification_version: 4
112
112
  summary: A simple utility to write a note.
data/.travis.yml DELETED
@@ -1,6 +0,0 @@
1
- ---
2
- language: ruby
3
- cache: bundler
4
- rvm:
5
- - 2.7.2
6
- before_install: gem install bundler -v 2.1.4