yn 0.1.0
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 +7 -0
- data/.editorconfig +11 -0
- data/.gitignore +13 -0
- data/.overcommit.yml +33 -0
- data/.rspec +3 -0
- data/.rubocop.yml +24 -0
- data/.travis.yml +21 -0
- data/.yardopts +1 -0
- data/.yardstick.yml +29 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Guardfile +20 -0
- data/LICENSE.txt +21 -0
- data/README.md +131 -0
- data/Rakefile +37 -0
- data/bin/console +7 -0
- data/bin/setup +14 -0
- data/lib/yn.rb +20 -0
- data/lib/yn/lenient.rb +93 -0
- data/lib/yn/version.rb +3 -0
- data/yn.gemspec +49 -0
- metadata +319 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 76494b0413198d1dddc1193c3dad64ed0ef784833844e297c921762705d907d1
|
4
|
+
data.tar.gz: 83d86d57e2e03730107cadf8cc85edc78e9b16e102e8e035f94da4b26c12a43e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fbd71cca44cedd5680ece2c4c93b4ec6ccac380a9631d05c43772a3d0ef4948ca75aa482774d86780ace89975a2230946ceebcf5631468d83b8643104b24e6c6
|
7
|
+
data.tar.gz: d37e0a1f046fc710722ec07f4f978f9f67ee935afc7435e9034caf88b934013d2046daa33f4326665143a45869f2e5652d536cd93895f8e77f73ae110b76db64
|
data/.editorconfig
ADDED
data/.gitignore
ADDED
data/.overcommit.yml
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Use this file to configure the Overcommit hooks you wish to use. This will
|
2
|
+
# extend the default configuration defined in:
|
3
|
+
# https://github.com/sds/overcommit/blob/master/config/default.yml
|
4
|
+
#
|
5
|
+
# At the topmost level of this YAML file is a key representing type of hook
|
6
|
+
# being run (e.g. pre-commit, commit-msg, etc.). Within each type you can
|
7
|
+
# customize each hook, such as whether to only run it on certain files (via
|
8
|
+
# `include`), whether to only display output if it fails (via `quiet`), etc.
|
9
|
+
#
|
10
|
+
# For a complete list of hooks, see:
|
11
|
+
# https://github.com/sds/overcommit/tree/master/lib/overcommit/hook
|
12
|
+
#
|
13
|
+
# For a complete list of options that you can use to customize hooks, see:
|
14
|
+
# https://github.com/sds/overcommit#configuration
|
15
|
+
#
|
16
|
+
# Uncomment the following lines to make the configuration take effect.
|
17
|
+
|
18
|
+
PreCommit:
|
19
|
+
RuboCop:
|
20
|
+
enabled: true
|
21
|
+
on_warn: fail # Treat all warnings as failures
|
22
|
+
|
23
|
+
# TrailingWhitespace:
|
24
|
+
# enabled: true
|
25
|
+
# exclude:
|
26
|
+
# - '**/db/structure.sql' # Ignore trailing whitespace in generated files
|
27
|
+
#
|
28
|
+
#PostCheckout:
|
29
|
+
# ALL: # Special hook name that customizes all hooks of this type
|
30
|
+
# quiet: true # Change all post-checkout hooks to only display output on failure
|
31
|
+
#
|
32
|
+
# IndexTags:
|
33
|
+
# enabled: true # Generate a tags file with `ctags` each time HEAD changes
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require: rubocop-rspec
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
DisplayCopNames: true
|
5
|
+
|
6
|
+
# ---------------------- Metrics ----------------------
|
7
|
+
|
8
|
+
Metrics/BlockLength:
|
9
|
+
Exclude:
|
10
|
+
- spec/**/*_spec.rb
|
11
|
+
- yn.gemspec
|
12
|
+
|
13
|
+
Metrics/LineLength:
|
14
|
+
Max: 120
|
15
|
+
|
16
|
+
# ----------------------- RSpec -----------------------
|
17
|
+
|
18
|
+
RSpec/ExampleLength:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
# ----------------------- Style -----------------------
|
22
|
+
|
23
|
+
Style/FrozenStringLiteralComment:
|
24
|
+
Enabled: false
|
data/.travis.yml
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
---
|
2
|
+
sudo: false
|
3
|
+
language: ruby
|
4
|
+
cache: bundler
|
5
|
+
rvm:
|
6
|
+
- 2.6.5
|
7
|
+
before_install: gem install bundler -v 2.0.2
|
8
|
+
|
9
|
+
before_script:
|
10
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
11
|
+
- chmod +x ./cc-test-reporter
|
12
|
+
- ./cc-test-reporter before-build
|
13
|
+
|
14
|
+
script:
|
15
|
+
- bundle exec bundle-audit
|
16
|
+
- bundle exec rspec
|
17
|
+
- bundle exec rubocop
|
18
|
+
- bundle exec rake yard:junk
|
19
|
+
|
20
|
+
after_script:
|
21
|
+
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
|
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--plugin junk
|
data/.yardstick.yml
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
threshold: 100
|
2
|
+
rules:
|
3
|
+
ApiTag::Presence:
|
4
|
+
enabled: false
|
5
|
+
exclude: []
|
6
|
+
ApiTag::Inclusion:
|
7
|
+
enabled: false
|
8
|
+
exclude: []
|
9
|
+
ApiTag::ProtectedMethod:
|
10
|
+
enabled: true
|
11
|
+
exclude: []
|
12
|
+
ApiTag::PrivateMethod:
|
13
|
+
enabled: true
|
14
|
+
exclude: []
|
15
|
+
ExampleTag:
|
16
|
+
enabled: false
|
17
|
+
exclude:
|
18
|
+
ReturnTag:
|
19
|
+
enabled: false
|
20
|
+
Summary::Presence:
|
21
|
+
enabled: false
|
22
|
+
Summary::Length:
|
23
|
+
enabled: false
|
24
|
+
Summary::Delimiter:
|
25
|
+
enabled: false
|
26
|
+
exclude: []
|
27
|
+
Summary::SingleLine:
|
28
|
+
enabled: false
|
29
|
+
exclude: []
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at wilson.dsigns@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
guard :bundler do
|
2
|
+
watch('yn.gemspec')
|
3
|
+
end
|
4
|
+
|
5
|
+
guard :bundler_audit, run_on_start: true do
|
6
|
+
watch('Gemfile.lock')
|
7
|
+
end
|
8
|
+
|
9
|
+
group :tests do
|
10
|
+
guard :rspec, all_on_start: true, cmd: 'COVERAGE=false bundle exec rspec --format progress' do
|
11
|
+
watch(%r{^spec/.+_spec\.rb$})
|
12
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
13
|
+
watch('spec/spec_helper.rb') { 'spec' }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
guard :rubocop do
|
18
|
+
watch(/.+\.rb$/)
|
19
|
+
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
|
20
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Wilson Silva
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
# Yn
|
2
|
+
|
3
|
+
[](https://badge.fury.io/rb/yn)
|
4
|
+
[](https://travis-ci.org/wilsonsilva/yn)
|
5
|
+
[](https://hakiri.io/github/wilsonsilva/yn/master)
|
6
|
+
[](http://inch-ci.org/github/wilsonsilva/yn)
|
7
|
+
|
8
|
+
|
9
|
+
> Parse yes/no like values
|
10
|
+
|
11
|
+
Useful for validating answers of a CLI prompt.
|
12
|
+
|
13
|
+
---
|
14
|
+
|
15
|
+
The following case-insensitive values are recognized:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
'y', 'yes', 'true', true, '1', 1, 'n', 'no', 'false', false, '0', 0, 'on', 'off'
|
19
|
+
```
|
20
|
+
|
21
|
+
*Enable lenient mode to gracefully handle typos.*
|
22
|
+
|
23
|
+
## Installation
|
24
|
+
|
25
|
+
Add this line to your application's Gemfile:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
gem 'yn'
|
29
|
+
```
|
30
|
+
|
31
|
+
And then execute:
|
32
|
+
|
33
|
+
$ bundle
|
34
|
+
|
35
|
+
Or install it yourself as:
|
36
|
+
|
37
|
+
$ gem install yn
|
38
|
+
|
39
|
+
## Usage
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
require 'yn'
|
43
|
+
|
44
|
+
Yn.parse('y')
|
45
|
+
# => true
|
46
|
+
|
47
|
+
Yn.parse('NO')
|
48
|
+
# => false
|
49
|
+
|
50
|
+
Yn.parse(true)
|
51
|
+
# => true
|
52
|
+
|
53
|
+
Yn.parse('abomasum')
|
54
|
+
# => nil
|
55
|
+
|
56
|
+
Yn.parse('abomasum', default: false)
|
57
|
+
# => false
|
58
|
+
|
59
|
+
Yn.parse('mo', lenient: true)
|
60
|
+
# => false
|
61
|
+
```
|
62
|
+
|
63
|
+
Unrecognized values return `nil`.
|
64
|
+
|
65
|
+
## API
|
66
|
+
|
67
|
+
### Yn.parse(input, options?)
|
68
|
+
|
69
|
+
#### input
|
70
|
+
|
71
|
+
Type: `unknown`
|
72
|
+
|
73
|
+
Value that should be converted.
|
74
|
+
|
75
|
+
#### options
|
76
|
+
|
77
|
+
Type: `hash`
|
78
|
+
|
79
|
+
##### lenient
|
80
|
+
|
81
|
+
Type: `boolean`\
|
82
|
+
Default: `false`
|
83
|
+
|
84
|
+
Use a key distance-based score to leniently accept typos of `yes` and `no`.
|
85
|
+
|
86
|
+
##### default
|
87
|
+
|
88
|
+
Type: `boolean`\
|
89
|
+
Default: `nil`
|
90
|
+
|
91
|
+
Default value if no match was found.
|
92
|
+
|
93
|
+
## Development
|
94
|
+
|
95
|
+
After checking out the repo, run `bin/setup` to install dependencies, configure git hooks and create support files.
|
96
|
+
|
97
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
98
|
+
|
99
|
+
The health and maintainability of the codebase is ensured through a set of
|
100
|
+
Rake tasks to test, lint and audit the gem for security vulnerabilities and documentation:
|
101
|
+
|
102
|
+
```
|
103
|
+
rake bundle:audit # Checks for vulnerable versions of gems
|
104
|
+
rake qa # Test, lint and perform security and documentation audits
|
105
|
+
rake rubocop # Lint the codebase with RuboCop
|
106
|
+
rake rubocop:auto_correct # Auto-correct RuboCop offenses
|
107
|
+
rake spec # Run RSpec code examples
|
108
|
+
rake verify_measurements # Verify that yardstick coverage is at least 100%
|
109
|
+
rake yard # Generate YARD Documentation
|
110
|
+
rake yard:junk # Check the junk in your YARD Documentation
|
111
|
+
rake yardstick_measure # Measure docs in lib/**/*.rb with yardstick
|
112
|
+
```
|
113
|
+
## Contributing
|
114
|
+
|
115
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/wilsonsilva/yn.
|
116
|
+
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to
|
117
|
+
adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
118
|
+
|
119
|
+
## License
|
120
|
+
|
121
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
122
|
+
|
123
|
+
## Credits
|
124
|
+
|
125
|
+
This is a port of [Sindre Sorhus](https://github.com/sindresorhus) JavaScript's [yn](https://github.com/sindresorhus/yn)
|
126
|
+
. I'm a big fan of his work!
|
127
|
+
|
128
|
+
## Code of Conduct
|
129
|
+
|
130
|
+
Everyone interacting in the Yn project’s codebases, issue trackers, chat rooms and mailing lists
|
131
|
+
is expected to follow the [code of conduct](https://github.com/wilsonsilva/yn/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'bundler/audit/task'
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
require 'rubocop/rake_task'
|
5
|
+
require 'yaml'
|
6
|
+
require 'yard/rake/yardoc_task'
|
7
|
+
require 'yard-junk/rake'
|
8
|
+
require 'yardstick/rake/measurement'
|
9
|
+
require 'yardstick/rake/verify'
|
10
|
+
|
11
|
+
yardstick_options = YAML.load_file('.yardstick.yml')
|
12
|
+
|
13
|
+
Bundler::Audit::Task.new
|
14
|
+
RuboCop::RakeTask.new
|
15
|
+
RSpec::Core::RakeTask.new(:spec)
|
16
|
+
YARD::Rake::YardocTask.new
|
17
|
+
YardJunk::Rake.define_task
|
18
|
+
Yardstick::Rake::Measurement.new(:yardstick_measure, yardstick_options)
|
19
|
+
Yardstick::Rake::Verify.new
|
20
|
+
|
21
|
+
task default: :spec
|
22
|
+
|
23
|
+
# Remove the report on rake clobber
|
24
|
+
CLEAN.include('measurements', 'doc', '.yardoc', 'tmp')
|
25
|
+
|
26
|
+
# Delete these files and folders when running rake clobber.
|
27
|
+
CLOBBER.include('coverage', '.rspec_status')
|
28
|
+
|
29
|
+
desc 'Run spec with coverage'
|
30
|
+
task :coverage do
|
31
|
+
ENV['COVERAGE'] = 'true'
|
32
|
+
Rake::Task['spec'].execute
|
33
|
+
`open coverage/index.html`
|
34
|
+
end
|
35
|
+
|
36
|
+
desc 'Test, lint and perform security and documentation audits'
|
37
|
+
task qa: %w[spec rubocop yard:junk verify_measurements bundle:audit]
|
data/bin/console
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
set -euo pipefail
|
3
|
+
IFS=$'\n\t'
|
4
|
+
set -vx
|
5
|
+
|
6
|
+
bundle install
|
7
|
+
|
8
|
+
if ! which overcommit >/dev/null; then
|
9
|
+
echo 'The gem overcommit is not installed. It is necessary to lint the git history through git hooks.'
|
10
|
+
echo 'Please install overcommit and run this script again.'
|
11
|
+
exit 1
|
12
|
+
fi
|
13
|
+
|
14
|
+
overcommit --install
|
data/lib/yn.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'yn/version'
|
2
|
+
require 'yn/lenient'
|
3
|
+
|
4
|
+
# Encapsulates all the code of the gem in a meaningful namespace.
|
5
|
+
module Yn
|
6
|
+
def self.parse(input, lenient: false, default: nil)
|
7
|
+
input = input.to_s.strip
|
8
|
+
|
9
|
+
unless [NilClass, TrueClass, FalseClass].include?(default.class)
|
10
|
+
raise ArgumentError, "Expected the 'default' option to be nil or a boolean, got #{default.class}"
|
11
|
+
end
|
12
|
+
|
13
|
+
return true if /^(?:y|yes|true|1|on)$/i.match?(input)
|
14
|
+
return false if /^(?:n|no|false|0|off)$/i.match?(input)
|
15
|
+
|
16
|
+
return Lenient.new.call(input, default) if lenient == true
|
17
|
+
|
18
|
+
default
|
19
|
+
end
|
20
|
+
end
|
data/lib/yn/lenient.rb
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
# Encapsulates all the code of the gem in a meaningful namespace.
|
2
|
+
module Yn
|
3
|
+
# Allows very small typos in the inputs.
|
4
|
+
class Lenient
|
5
|
+
YES_MATCH_SCORE_THRESHOLD = 2
|
6
|
+
NO_MATCH_SCORE_THRESHOLD = 1.25
|
7
|
+
|
8
|
+
Y_MATCH = [
|
9
|
+
[5, 0.25],
|
10
|
+
[6, 0.25],
|
11
|
+
[7, 0.25],
|
12
|
+
['t', 0.75],
|
13
|
+
['y', 1],
|
14
|
+
['u', 0.75],
|
15
|
+
['g', 0.25],
|
16
|
+
['h', 0.25],
|
17
|
+
['j', 0.25]
|
18
|
+
].to_h
|
19
|
+
|
20
|
+
E_MATCH = [
|
21
|
+
[2, 0.25],
|
22
|
+
[3, 0.25],
|
23
|
+
[4, 0.25],
|
24
|
+
['w', 0.75],
|
25
|
+
['e', 1],
|
26
|
+
['r', 0.75],
|
27
|
+
['s', 0.25],
|
28
|
+
['d', 0.25],
|
29
|
+
['f', 0.25]
|
30
|
+
].to_h
|
31
|
+
|
32
|
+
S_MATCH = [
|
33
|
+
['q', 0.25],
|
34
|
+
['w', 0.25],
|
35
|
+
['e', 0.25],
|
36
|
+
['a', 0.75],
|
37
|
+
['s', 1],
|
38
|
+
['d', 0.75],
|
39
|
+
['z', 0.25],
|
40
|
+
['x', 0.25],
|
41
|
+
['c', 0.25]
|
42
|
+
].to_h
|
43
|
+
|
44
|
+
N_MATCH = [
|
45
|
+
['h', 0.25],
|
46
|
+
['j', 0.25],
|
47
|
+
['k', 0.25],
|
48
|
+
['b', 0.75],
|
49
|
+
['n', 1],
|
50
|
+
['m', 0.75]
|
51
|
+
].to_h
|
52
|
+
|
53
|
+
O_MATCH = [
|
54
|
+
[9, 0.25],
|
55
|
+
[0, 0.25],
|
56
|
+
['i', 0.75],
|
57
|
+
['o', 1],
|
58
|
+
['p', 0.75],
|
59
|
+
['k', 0.25],
|
60
|
+
['l', 0.25]
|
61
|
+
].to_h
|
62
|
+
|
63
|
+
def call(input, default)
|
64
|
+
return true if get_yes_match_score(input) >= YES_MATCH_SCORE_THRESHOLD
|
65
|
+
return false if get_no_match_score(input) >= NO_MATCH_SCORE_THRESHOLD
|
66
|
+
|
67
|
+
default
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def get_yes_match_score(input)
|
73
|
+
y, e, s = input.split('')
|
74
|
+
|
75
|
+
score = 0
|
76
|
+
score += Y_MATCH.fetch(y) if Y_MATCH.key?(y)
|
77
|
+
score += E_MATCH.fetch(e) if E_MATCH.key?(e)
|
78
|
+
score += S_MATCH.fetch(s) if S_MATCH.key?(s)
|
79
|
+
score
|
80
|
+
end
|
81
|
+
|
82
|
+
def get_no_match_score(input)
|
83
|
+
n, o = input.split('')
|
84
|
+
|
85
|
+
score = 0
|
86
|
+
score += N_MATCH.fetch(n) if N_MATCH.key?(n)
|
87
|
+
score += O_MATCH.fetch(o) if O_MATCH.key?(o)
|
88
|
+
score
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
private_constant :Lenient
|
93
|
+
end
|
data/lib/yn/version.rb
ADDED
data/yn.gemspec
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
|
4
|
+
require 'yn/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'yn'
|
8
|
+
spec.version = Yn::VERSION
|
9
|
+
spec.authors = ['Wilson Silva']
|
10
|
+
spec.email = ['me@wilsonsilva.net']
|
11
|
+
|
12
|
+
spec.summary = 'Parse yes/no like values.'
|
13
|
+
spec.description = 'Parse yes/no like values. Port of https://github.com/sindresorhus/yn.'
|
14
|
+
spec.homepage = 'https://github.com/wilsonsilva/yn'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
18
|
+
spec.metadata['source_code_uri'] = 'https://github.com/wilsonsilva/yn'
|
19
|
+
spec.metadata['changelog_uri'] = 'https://github.com/wilsonsilva/yn/blob/master/CHANGELOG.md'
|
20
|
+
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
|
+
end
|
26
|
+
|
27
|
+
spec.bindir = 'exe'
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ['lib']
|
30
|
+
|
31
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
32
|
+
spec.add_development_dependency 'bundler-audit', '~> 0.6'
|
33
|
+
spec.add_development_dependency 'guard', '~> 2.16'
|
34
|
+
spec.add_development_dependency 'guard-bundler', '~> 2.2'
|
35
|
+
spec.add_development_dependency 'guard-bundler-audit', '~> 0.1'
|
36
|
+
spec.add_development_dependency 'guard-rspec', '~> 4.7'
|
37
|
+
spec.add_development_dependency 'guard-rubocop', '~> 1.3'
|
38
|
+
spec.add_development_dependency 'overcommit', '~> 0.51'
|
39
|
+
spec.add_development_dependency 'pry', '~> 0.12'
|
40
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
41
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
42
|
+
spec.add_development_dependency 'rubocop', '~> 0.77'
|
43
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 1.37'
|
44
|
+
spec.add_development_dependency 'simplecov', '~> 0.17'
|
45
|
+
spec.add_development_dependency 'simplecov-console', '~> 0.6'
|
46
|
+
spec.add_development_dependency 'yard', '~> 0.9'
|
47
|
+
spec.add_development_dependency 'yard-junk', '~> 0.0.7'
|
48
|
+
spec.add_development_dependency 'yardstick', '~> 0.9'
|
49
|
+
end
|
metadata
ADDED
@@ -0,0 +1,319 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yn
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Wilson Silva
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-12-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler-audit
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: guard
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.16'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.16'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: guard-bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: guard-bundler-audit
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.1'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.1'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard-rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '4.7'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '4.7'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: guard-rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.3'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.3'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: overcommit
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.51'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.51'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: pry
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0.12'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0.12'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rake
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '10.0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '10.0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: rspec
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '3.0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '3.0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: rubocop
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0.77'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - "~>"
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0.77'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: rubocop-rspec
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - "~>"
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '1.37'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - "~>"
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '1.37'
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: simplecov
|
197
|
+
requirement: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - "~>"
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0.17'
|
202
|
+
type: :development
|
203
|
+
prerelease: false
|
204
|
+
version_requirements: !ruby/object:Gem::Requirement
|
205
|
+
requirements:
|
206
|
+
- - "~>"
|
207
|
+
- !ruby/object:Gem::Version
|
208
|
+
version: '0.17'
|
209
|
+
- !ruby/object:Gem::Dependency
|
210
|
+
name: simplecov-console
|
211
|
+
requirement: !ruby/object:Gem::Requirement
|
212
|
+
requirements:
|
213
|
+
- - "~>"
|
214
|
+
- !ruby/object:Gem::Version
|
215
|
+
version: '0.6'
|
216
|
+
type: :development
|
217
|
+
prerelease: false
|
218
|
+
version_requirements: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - "~>"
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: '0.6'
|
223
|
+
- !ruby/object:Gem::Dependency
|
224
|
+
name: yard
|
225
|
+
requirement: !ruby/object:Gem::Requirement
|
226
|
+
requirements:
|
227
|
+
- - "~>"
|
228
|
+
- !ruby/object:Gem::Version
|
229
|
+
version: '0.9'
|
230
|
+
type: :development
|
231
|
+
prerelease: false
|
232
|
+
version_requirements: !ruby/object:Gem::Requirement
|
233
|
+
requirements:
|
234
|
+
- - "~>"
|
235
|
+
- !ruby/object:Gem::Version
|
236
|
+
version: '0.9'
|
237
|
+
- !ruby/object:Gem::Dependency
|
238
|
+
name: yard-junk
|
239
|
+
requirement: !ruby/object:Gem::Requirement
|
240
|
+
requirements:
|
241
|
+
- - "~>"
|
242
|
+
- !ruby/object:Gem::Version
|
243
|
+
version: 0.0.7
|
244
|
+
type: :development
|
245
|
+
prerelease: false
|
246
|
+
version_requirements: !ruby/object:Gem::Requirement
|
247
|
+
requirements:
|
248
|
+
- - "~>"
|
249
|
+
- !ruby/object:Gem::Version
|
250
|
+
version: 0.0.7
|
251
|
+
- !ruby/object:Gem::Dependency
|
252
|
+
name: yardstick
|
253
|
+
requirement: !ruby/object:Gem::Requirement
|
254
|
+
requirements:
|
255
|
+
- - "~>"
|
256
|
+
- !ruby/object:Gem::Version
|
257
|
+
version: '0.9'
|
258
|
+
type: :development
|
259
|
+
prerelease: false
|
260
|
+
version_requirements: !ruby/object:Gem::Requirement
|
261
|
+
requirements:
|
262
|
+
- - "~>"
|
263
|
+
- !ruby/object:Gem::Version
|
264
|
+
version: '0.9'
|
265
|
+
description: Parse yes/no like values. Port of https://github.com/sindresorhus/yn.
|
266
|
+
email:
|
267
|
+
- me@wilsonsilva.net
|
268
|
+
executables: []
|
269
|
+
extensions: []
|
270
|
+
extra_rdoc_files: []
|
271
|
+
files:
|
272
|
+
- ".editorconfig"
|
273
|
+
- ".gitignore"
|
274
|
+
- ".overcommit.yml"
|
275
|
+
- ".rspec"
|
276
|
+
- ".rubocop.yml"
|
277
|
+
- ".travis.yml"
|
278
|
+
- ".yardopts"
|
279
|
+
- ".yardstick.yml"
|
280
|
+
- CHANGELOG.md
|
281
|
+
- CODE_OF_CONDUCT.md
|
282
|
+
- Gemfile
|
283
|
+
- Guardfile
|
284
|
+
- LICENSE.txt
|
285
|
+
- README.md
|
286
|
+
- Rakefile
|
287
|
+
- bin/console
|
288
|
+
- bin/setup
|
289
|
+
- lib/yn.rb
|
290
|
+
- lib/yn/lenient.rb
|
291
|
+
- lib/yn/version.rb
|
292
|
+
- yn.gemspec
|
293
|
+
homepage: https://github.com/wilsonsilva/yn
|
294
|
+
licenses:
|
295
|
+
- MIT
|
296
|
+
metadata:
|
297
|
+
homepage_uri: https://github.com/wilsonsilva/yn
|
298
|
+
source_code_uri: https://github.com/wilsonsilva/yn
|
299
|
+
changelog_uri: https://github.com/wilsonsilva/yn/blob/master/CHANGELOG.md
|
300
|
+
post_install_message:
|
301
|
+
rdoc_options: []
|
302
|
+
require_paths:
|
303
|
+
- lib
|
304
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
305
|
+
requirements:
|
306
|
+
- - ">="
|
307
|
+
- !ruby/object:Gem::Version
|
308
|
+
version: '0'
|
309
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
310
|
+
requirements:
|
311
|
+
- - ">="
|
312
|
+
- !ruby/object:Gem::Version
|
313
|
+
version: '0'
|
314
|
+
requirements: []
|
315
|
+
rubygems_version: 3.0.3
|
316
|
+
signing_key:
|
317
|
+
specification_version: 4
|
318
|
+
summary: Parse yes/no like values.
|
319
|
+
test_files: []
|