howzit 2.1.13 → 2.1.14

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: f0fc931036b21c7bb13c805751a146432d14c40a9a910fd9999aa42fb34658cb
4
- data.tar.gz: 31b927c85e4c7ba6938eff929e7670c1a997d79f21053ce230da3a1a5ca4b246
3
+ metadata.gz: 1fa016c0fa681b1f07238f643dcdffd1fe9679a0362dd18a99ad5c9280282a66
4
+ data.tar.gz: 2e171f199e644a56046121b4a2b7bc803196bee9b026f619939c51f70828ec13
5
5
  SHA512:
6
- metadata.gz: 6382fd78151da4a021d605276121fc48f0b1cb7692ee3a4657fd4dee820577f0f5357aa98be565dd120e440619906b1881da2269fe0e53c2321160a34dee26ac
7
- data.tar.gz: d402a1dcf7715f04ed32fc282450c4132bf13cd3a43830eb464c298f79dc86fa4c47f30a6bd8d3698e588468f107b0b4eae6ad90c89195d878ef1f610846ab78
6
+ metadata.gz: 5178be93f700a6d51ddee37f1ea239d65eab8c79f60773d4a8faa9f6dc191a195d43e725cb9980532b2ab177a332c86fe0b914d64051c1eb67c80df0f1c61104
7
+ data.tar.gz: 58490e3f05c46aba51248dc857f1835b8146f9bfcd7b76fa0640175140046676825a4d1e25f1824bac5415875857da0078a95d2f4dbc783e0bf69d90e42c3c05
data/.irbrc ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+ `gem rdoc binbundle --ri`
3
+
4
+ # rubocop:disable Style/MixinUsage
5
+ include Howzit # standard:disable all
6
+ # rubocop:enable Style/MixinUsage
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ### 2.1.14
2
+
3
+ 2024-08-06 16:36
4
+
5
+ #### IMPROVED
6
+
7
+ - Better algorithm for best match when `multiple_matches: best` is set
8
+
1
9
  ### 2.1.13
2
10
 
3
11
  2024-08-05 12:04
data/README.md CHANGED
@@ -2,13 +2,13 @@
2
2
  # Howzit
3
3
 
4
4
  [![Gem](https://img.shields.io/gem/v/howzit.svg)](https://rubygems.org/gems/howzit)
5
- [![Travis](https://api.travis-ci.com/ttscoff/howzit.svg?branch=main)](https://travis-ci.org/makenew/ruby-gem)
6
5
  [![GitHub license](https://img.shields.io/github/license/ttscoff/howzit.svg)](./LICENSE.txt)
7
6
 
8
7
  A command-line reference tool for tracking project build systems
9
8
 
10
9
  Howzit is a tool that allows you to keep Markdown-formatted notes about a project's tools and procedures. It functions as an easy lookup for notes about a particular task, as well as a task runner to automatically execute appropriate commands.
11
10
 
11
+
12
12
  ## Features
13
13
 
14
14
  - Match topic titles with any portion of title
@@ -780,7 +780,7 @@ module Howzit
780
780
  when :first
781
781
  topic_matches.push(matches[0])
782
782
  when :best
783
- topic_matches.push(matches.sort.min_by { |t| t.title.length })
783
+ topic_matches.push(matches.sort_by { |a| [a.title.comp_distance(s), a.title.length] })
784
784
  when :all
785
785
  topic_matches.concat(matches)
786
786
  else
@@ -3,6 +3,86 @@
3
3
  module Howzit
4
4
  # String Extensions
5
5
  module StringUtils
6
+ ## Compare strings and return a distance
7
+ ##
8
+ ## @param other [String] The string to compare
9
+ ## @param term [String] The search term
10
+ ##
11
+ ## @return [Float] distance
12
+ def comp_distance(term)
13
+ chars = term.split(//)
14
+ contains_count(chars) + distance(chars)
15
+ end
16
+
17
+ ##
18
+ ## Number of matching characters the string contains
19
+ ##
20
+ ## @param chars [String|Array] The characters
21
+ ##
22
+ def contains_count(chars)
23
+ chars = chars.split(//) if chars.is_a?(String)
24
+ count = 0
25
+ chars.each { |char| count += 1 if self =~ /#{char}/i }
26
+ count
27
+ end
28
+
29
+ ##
30
+ ## Determine if characters are in order
31
+ ##
32
+ ## @param chars [String|Array] The characters
33
+ ##
34
+ ## @return [Boolean] characters are in order
35
+ ##
36
+ def in_order(chars)
37
+ chars = chars.split(//) if chars.is_a?(String)
38
+ position = 0
39
+ in_order = 0
40
+ chars.each do |char|
41
+ new_pos = self[position..] =~ /#{char}/i
42
+ if new_pos
43
+ position += new_pos
44
+ in_order += 1
45
+ end
46
+ end
47
+ in_order
48
+ end
49
+
50
+ ##
51
+ ## Determine if a series of characters are all within a given distance of
52
+ ## each other in the String
53
+ ##
54
+ ## @param chars [String|Array] The characters
55
+ ## @param distance [Number] The distance
56
+ ##
57
+ ## @return [Boolean] true if within distance
58
+ ##
59
+ def in_distance?(chars, distance)
60
+ chars = chars.split(//) if chars.is_a?(String)
61
+ rx = Regexp.new(chars.join(".{,#{distance}}"), 'i')
62
+ self =~ rx ? true : false
63
+ end
64
+
65
+ ##
66
+ ## Determine the minimum distance between characters that they all still
67
+ ## fall within
68
+ ##
69
+ ## @param chars [Array] The characters
70
+ ##
71
+ ## @return [Number] distance
72
+ ##
73
+ def distance(chars)
74
+ distance = 0
75
+ max = self.length - chars.length
76
+ return max unless in_order(chars) == chars.length
77
+
78
+ while distance < max
79
+ return distance if in_distance?(chars, distance)
80
+
81
+ distance += 1
82
+ end
83
+ distance
84
+ end
85
+
6
86
  ##
7
87
  ## Test if the filename matches the conditions to be a build note
8
88
  ##
@@ -3,5 +3,5 @@
3
3
  # Primary module for this gem.
4
4
  module Howzit
5
5
  # Current Howzit version.
6
- VERSION = '2.1.13'
6
+ VERSION = '2.1.14'
7
7
  end
@@ -27,43 +27,55 @@ describe Howzit::BuildNote do
27
27
  expect(matches.count).to eq 1
28
28
  expect(matches[0].title).to eq 'Topic Tropic'
29
29
  end
30
+
30
31
  it "fuzzy matches" do
31
32
  Howzit.options[:matching] = 'fuzzy'
32
33
  matches = how.find_topic('trpc')
33
34
  expect(matches.count).to eq 1
34
35
  expect(matches[0].title).to eq 'Topic Tropic'
35
36
  end
37
+
36
38
  it "succeeds with partial match" do
37
39
  Howzit.options[:matching] = 'partial'
38
40
  matches = how.find_topic('trop')
39
41
  expect(matches.count).to eq 1
40
42
  expect(matches[0].title).to eq 'Topic Tropic'
41
43
  end
44
+
42
45
  it "succeeds with beginswith match" do
43
46
  Howzit.options[:matching] = 'beginswith'
44
47
  matches = how.find_topic('topic')
45
48
  expect(matches.count).to eq 3
46
49
  expect(matches[0].title).to eq 'Topic Balogna'
47
50
  end
51
+
48
52
  it "succeeds with exact match" do
49
53
  Howzit.options[:matching] = 'exact'
50
54
  matches = how.find_topic('topic tropic')
51
55
  expect(matches.count).to eq 1
52
56
  expect(matches[0].title).to eq 'Topic Tropic'
53
57
  end
58
+
54
59
  it "fails with incomplete exact match" do
55
60
  Howzit.options[:matching] = 'exact'
56
61
  matches = how.find_topic('topic trop')
57
62
  expect(matches.count).to eq 0
58
63
  end
64
+
65
+ it "Handles multiple matches with best match" do
66
+ Howzit.options[:matching] = 'fuzzy'
67
+ Howzit.options[:multiple_matches] = :best
68
+ matches = how.find_topic('banana')
69
+ expect(matches.first.title).to match(/banana/i)
70
+ end
59
71
  end
60
72
 
61
73
  describe ".topics" do
62
74
  it "contains 4 topics" do
63
- expect(how.list_topics.count).to eq 3
75
+ expect(how.list_topics.count).to eq 4
64
76
  end
65
77
  it "outputs a newline-separated string for completion" do
66
- expect(how.list_completions.scan(/\n/).count).to eq 2
78
+ expect(how.list_completions.scan(/\n/).count).to eq 3
67
79
  end
68
80
  end
69
81
  end
data/spec/cli_spec.rb CHANGED
@@ -15,7 +15,7 @@ describe 'CLI' do
15
15
  execute_script('bin/howzit', use_bundler: true, args: %w[-L])
16
16
  expect(last_execution).to be_successful
17
17
  expect(last_execution.stdout).to match(/Topic Balogna/)
18
- expect(last_execution.stdout.split(/\n/).count).to eq 3
18
+ expect(last_execution.stdout.split(/\n/).count).to eq 4
19
19
  end
20
20
 
21
21
  it 'lists available tasks' do
data/spec/spec_helper.rb CHANGED
@@ -63,6 +63,10 @@ def save_buildnote
63
63
 
64
64
  Bermuda, Bahama, something something wanna.
65
65
  @copy(Balogna) Just some balogna
66
+
67
+ ## Happy Bgagngagnga
68
+
69
+ This one is just to throw things off
66
70
  EONOTE
67
71
  File.open('builda.md', 'w') { |f| f.puts note }
68
72
  end
data/src/_README.md CHANGED
@@ -2,12 +2,12 @@
2
2
  # Howzit
3
3
 
4
4
  [![Gem](https://img.shields.io/gem/v/howzit.svg)](https://rubygems.org/gems/howzit)
5
- [![Travis](https://api.travis-ci.com/ttscoff/howzit.svg?branch=main)](https://travis-ci.org/makenew/ruby-gem)
6
5
  [![GitHub license](https://img.shields.io/github/license/ttscoff/howzit.svg)](./LICENSE.txt)
7
- <!--END GITHUB-->
6
+
8
7
  A command-line reference tool for tracking project build systems
9
8
 
10
9
  Howzit is a tool that allows you to keep Markdown-formatted notes about a project's tools and procedures. It functions as an easy lookup for notes about a particular task, as well as a task runner to automatically execute appropriate commands.
10
+ <!--END GITHUB-->
11
11
 
12
12
  ## Features
13
13
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: howzit
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.13
4
+ version: 2.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-05 00:00:00.000000000 Z
11
+ date: 2024-08-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -294,6 +294,7 @@ files:
294
294
  - ".github/FUNDING.yml"
295
295
  - ".gitignore"
296
296
  - ".howzit.taskpaper.bak"
297
+ - ".irbrc"
297
298
  - ".rspec"
298
299
  - ".rubocop.yml"
299
300
  - ".travis.yml"