did_you 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +3 -0
- data/README.md +43 -0
- data/did_you.gemspec +36 -0
- data/lib/did_you.rb +79 -0
- metadata +159 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1fb09003f8cd29e738be87c5fa3ca2d7fdc50076
|
4
|
+
data.tar.gz: 3aec1835191a0dce039885593655ac755dddf67e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f5990542239b70ddc9b6f803fd34a6acaeb7c0d7884119e98256a38ff0e272b7e7b25698f8fbc4a3914b9a5d1ea0913a8da787df2238cb4fab1061f811e7a8c9
|
7
|
+
data.tar.gz: 4f5f6ca86a4a8b5cfb2fc90996faca77051e9e2924843351b13e481892c24e655bc7d75d15c93ea397af57ee747c6123e74d63032202b059abe6f250a3029cb3
|
data/.yardopts
ADDED
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# `DidYou::Spell` -- small wrapper around `did_you_mean`
|
2
|
+
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/did_you.svg)](http://badge.fury.io/rb/did_you)
|
4
|
+
[![Build Status](https://travis-ci.org/zverok/did_you.svg?branch=master)](https://travis-ci.org/zverok/did_you)
|
5
|
+
|
6
|
+
Have you seen this thing in new Ruby (2.3+)?
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
(1..10).cover(2)
|
10
|
+
# NoMethodError: undefined method `cover' for 1..10:Range
|
11
|
+
# Did you mean? cover? <---- This
|
12
|
+
```
|
13
|
+
|
14
|
+
If you wanted to provide same functionality for your code ("Lexem `x` is not recognized. Did you
|
15
|
+
mean `y`?") you can use [did_you_mean](https://github.com/yuki24/did_you_mean) gem bundled with
|
16
|
+
your Ruby. But it is a bit hard: gem's dictionary lookup interface is a bit hard to follow, and
|
17
|
+
moreover, it changes dramatically from Ruby 2.3 to Ruby 2.4, and standalone gem version (available
|
18
|
+
for Ruby 2.1-2.2) has one more different interface.
|
19
|
+
|
20
|
+
`did_you` solves this problem by providing simple, Ruby version-agnostic inteface to `did_you_mean`
|
21
|
+
gem.
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Install it as a `gem did_you` or add `gem 'did_you'` to your `Gemfile`. (On Ruby < 2.3 it will install
|
26
|
+
old `did_you_mean`, on newer ones has no additional dependencies.)
|
27
|
+
|
28
|
+
Then just...
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
# First parameter is word you want to check, second -- known words in the context
|
32
|
+
DidYou::Spell.check('params', %w[param return tag abstract]) # => ["param"]
|
33
|
+
```
|
34
|
+
|
35
|
+
That's it. ¯\\\_(ツ)_/¯
|
36
|
+
|
37
|
+
## Author
|
38
|
+
|
39
|
+
[Victor Shepelev](https://github.com/zverok)
|
40
|
+
|
41
|
+
## License
|
42
|
+
|
43
|
+
MIT
|
data/did_you.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'did_you'
|
3
|
+
s.version = '0.0.1'
|
4
|
+
s.authors = ['Victor Shepelev']
|
5
|
+
s.email = 'zverok.offline@gmail.com'
|
6
|
+
s.homepage = 'https://github.com/zverok/did_you'
|
7
|
+
|
8
|
+
s.summary = 'Ruby version-agnostic wrapper for did_you_mean gem'
|
9
|
+
s.licenses = ['MIT']
|
10
|
+
|
11
|
+
s.required_ruby_version = '>= 2.1.0'
|
12
|
+
|
13
|
+
s.files = `git ls-files`.split($RS).reject do |file|
|
14
|
+
file =~ /^(?:
|
15
|
+
spec\/.*
|
16
|
+
|Gemfile
|
17
|
+
|Rakefile
|
18
|
+
|\.rspec
|
19
|
+
|\.gitignore
|
20
|
+
|\.rubocop.yml
|
21
|
+
|\.travis.yml
|
22
|
+
)$/x
|
23
|
+
end
|
24
|
+
s.require_paths = ['lib']
|
25
|
+
|
26
|
+
s.add_dependency 'did_you_mean' if RUBY_VERSION < '2.3'
|
27
|
+
|
28
|
+
s.add_development_dependency 'rspec'
|
29
|
+
s.add_development_dependency 'rspec-its'
|
30
|
+
s.add_development_dependency 'rubocop'
|
31
|
+
s.add_development_dependency 'yard'
|
32
|
+
s.add_development_dependency 'kramdown' # for YARD
|
33
|
+
s.add_development_dependency 'yard-junk', '>= 0.0.5'
|
34
|
+
s.add_development_dependency 'rake'
|
35
|
+
s.add_development_dependency 'rubygems-tasks'
|
36
|
+
end
|
data/lib/did_you.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'did_you_mean'
|
5
|
+
rescue LoadError # rubocop:disable Lint/HandleExceptions
|
6
|
+
end
|
7
|
+
|
8
|
+
# Very simple "did you mean" style suggestor, wrapping different
|
9
|
+
# versions of did_you_mean gem, both when bundled in Ruby (2.3+)
|
10
|
+
# and not bundled (2.1-2.2).
|
11
|
+
#
|
12
|
+
# @example
|
13
|
+
#
|
14
|
+
# DidYou::Spell.check('raise', %w[raise def class]) # => ["raise"]
|
15
|
+
# DidYou::Spell.check('rais', %w[raise]) # => []
|
16
|
+
#
|
17
|
+
# @see Spell.check
|
18
|
+
module DidYou
|
19
|
+
# See {.check}
|
20
|
+
module Spell
|
21
|
+
module_function
|
22
|
+
|
23
|
+
# Checks mistyped word against provided dictionary.
|
24
|
+
#
|
25
|
+
# @param error [String] Mistyped word (say, method name).
|
26
|
+
# @param dictionary [Array<String>] Dictionary of known words
|
27
|
+
# (say, defined methods).
|
28
|
+
# @return [Array<String>] List of suggested spellings or `[]`
|
29
|
+
# if word is correct or did_you_mean gem is not found.
|
30
|
+
#
|
31
|
+
def check(error, dictionary)
|
32
|
+
_check(error, dictionary) - [error]
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
module_function
|
38
|
+
|
39
|
+
if !Kernel.const_defined?(:DidYouMean)
|
40
|
+
STDERR.puts 'did_you_mean gem not found.'
|
41
|
+
def _check(*)
|
42
|
+
[]
|
43
|
+
end
|
44
|
+
elsif DidYouMean.const_defined?(:SpellCheckable) # 1.0 +
|
45
|
+
SpellChecker = Struct.new(:error, :dictionary) do
|
46
|
+
include DidYouMean::SpellCheckable
|
47
|
+
|
48
|
+
def candidates
|
49
|
+
{ error => dictionary }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def _check(error, dictionary)
|
54
|
+
SpellChecker.new(error, dictionary).corrections
|
55
|
+
end
|
56
|
+
elsif DidYouMean.const_defined?(:SpellChecker) # 1.1+
|
57
|
+
def _check(error, dictionary)
|
58
|
+
DidYouMean::SpellChecker.new(dictionary: dictionary).correct(error)
|
59
|
+
end
|
60
|
+
elsif DidYouMean.const_defined?(:BaseFinder) # < 1.0
|
61
|
+
SpellFinder = Struct.new(:error, :dictionary) do
|
62
|
+
include DidYouMean::BaseFinder
|
63
|
+
|
64
|
+
def searches
|
65
|
+
{ error => dictionary }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def _check(error, dictionary)
|
70
|
+
SpellFinder.new(error, dictionary).suggestions
|
71
|
+
end
|
72
|
+
else
|
73
|
+
STDERR.puts 'Unrecognized did_you_mean version. '
|
74
|
+
def check(*)
|
75
|
+
[]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
metadata
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: did_you
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Victor Shepelev
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-09-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec-its
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rubocop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: yard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: kramdown
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: yard-junk
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.0.5
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.0.5
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubygems-tasks
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
description:
|
126
|
+
email: zverok.offline@gmail.com
|
127
|
+
executables: []
|
128
|
+
extensions: []
|
129
|
+
extra_rdoc_files: []
|
130
|
+
files:
|
131
|
+
- ".yardopts"
|
132
|
+
- README.md
|
133
|
+
- did_you.gemspec
|
134
|
+
- lib/did_you.rb
|
135
|
+
homepage: https://github.com/zverok/did_you
|
136
|
+
licenses:
|
137
|
+
- MIT
|
138
|
+
metadata: {}
|
139
|
+
post_install_message:
|
140
|
+
rdoc_options: []
|
141
|
+
require_paths:
|
142
|
+
- lib
|
143
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ">="
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: 2.1.0
|
148
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
requirements: []
|
154
|
+
rubyforge_project:
|
155
|
+
rubygems_version: 2.6.10
|
156
|
+
signing_key:
|
157
|
+
specification_version: 4
|
158
|
+
summary: Ruby version-agnostic wrapper for did_you_mean gem
|
159
|
+
test_files: []
|