yn 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.yardstick.yml +6 -13
- data/CHANGELOG.md +14 -0
- data/CODE_OF_CONDUCT.md +1 -1
- data/README.md +4 -2
- data/lib/yn.rb +46 -0
- data/lib/yn/lenient.rb +27 -1
- data/lib/yn/version.rb +1 -1
- data/yn.gemspec +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e256eaf3264537746200a081ead79be85e33989e45e39252363f0ac3eb20a4d
|
4
|
+
data.tar.gz: d27bd13bec779a3e40eb0573581e681ef974ca837a7b8ce81a181075b4097213
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b37454e5970f5832d396243651e53af733acd9714281dea1b60bf7353db960f84b78b22f02aa25e08a836fb6cba3883a2b08644eaff97d3e840b61cd2f295bd2
|
7
|
+
data.tar.gz: 489f2ca931c71cfd6bbb58a600d5a91bfc288b1c052196c3919e570ffd1d60e04ed549e2d7a823bfd2618d3ead6382a8ec6c3233e1e4ee75df5f9dd47e957647
|
data/.yardstick.yml
CHANGED
@@ -1,29 +1,22 @@
|
|
1
1
|
threshold: 100
|
2
2
|
rules:
|
3
3
|
ApiTag::Presence:
|
4
|
-
enabled:
|
5
|
-
exclude: []
|
4
|
+
enabled: true
|
6
5
|
ApiTag::Inclusion:
|
7
|
-
enabled:
|
8
|
-
exclude: []
|
6
|
+
enabled: true
|
9
7
|
ApiTag::ProtectedMethod:
|
10
8
|
enabled: true
|
11
|
-
exclude: []
|
12
9
|
ApiTag::PrivateMethod:
|
13
10
|
enabled: true
|
14
|
-
exclude: []
|
15
11
|
ExampleTag:
|
16
|
-
enabled:
|
17
|
-
exclude:
|
12
|
+
enabled: true
|
18
13
|
ReturnTag:
|
19
|
-
enabled:
|
14
|
+
enabled: true
|
20
15
|
Summary::Presence:
|
21
|
-
enabled:
|
16
|
+
enabled: true
|
22
17
|
Summary::Length:
|
23
18
|
enabled: false
|
24
19
|
Summary::Delimiter:
|
25
|
-
enabled:
|
26
|
-
exclude: []
|
20
|
+
enabled: true
|
27
21
|
Summary::SingleLine:
|
28
22
|
enabled: false
|
29
|
-
exclude: []
|
data/CHANGELOG.md
CHANGED
@@ -3,3 +3,17 @@ All notable changes to this project will be documented in this file.
|
|
3
3
|
|
4
4
|
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
6
|
+
|
7
|
+
## [1.0.0] - 2019-12-01
|
8
|
+
### Changed
|
9
|
+
- Fully documented all classes and methods
|
10
|
+
- Required Ruby 2.3 or higher in the gemspec
|
11
|
+
### Added
|
12
|
+
- Integrated the gem with CodeClimate for code coverage and maintainability reports
|
13
|
+
|
14
|
+
## [0.1.0] - 2019-12-01
|
15
|
+
### Added
|
16
|
+
- Initial core functionality
|
17
|
+
- Codebase maintenance tools
|
18
|
+
|
19
|
+
[Unreleased]: https://github.com/wilsonsilva/yn/compare/v1.0.0...HEAD
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -55,7 +55,7 @@ further defined and clarified by project maintainers.
|
|
55
55
|
## Enforcement
|
56
56
|
|
57
57
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
-
reported by contacting the project team at
|
58
|
+
reported by contacting the project team at me@wilsonsiva.net All
|
59
59
|
complaints will be reviewed and investigated and will result in a response that
|
60
60
|
is deemed necessary and appropriate to the circumstances. The project team is
|
61
61
|
obligated to maintain confidentiality with regard to the reporter of an incident.
|
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/yn.svg)](https://badge.fury.io/rb/yn)
|
4
4
|
[![Build Status](https://travis-ci.org/wilsonsilva/yn.svg?branch=master)](https://travis-ci.org/wilsonsilva/yn)
|
5
|
+
[![Maintainability](https://api.codeclimate.com/v1/badges/96e1447d3ad45f1ca681/maintainability)](https://codeclimate.com/github/wilsonsilva/yn/maintainability)
|
6
|
+
[![Test Coverage](https://api.codeclimate.com/v1/badges/96e1447d3ad45f1ca681/test_coverage)](https://codeclimate.com/github/wilsonsilva/yn/test_coverage)
|
5
7
|
[![Security](https://hakiri.io/github/wilsonsilva/yn/master.svg)](https://hakiri.io/github/wilsonsilva/yn/master)
|
6
8
|
[![Inline docs](http://inch-ci.org/github/wilsonsilva/yn.svg?branch=master)](http://inch-ci.org/github/wilsonsilva/yn)
|
7
9
|
|
@@ -122,8 +124,8 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
122
124
|
|
123
125
|
## Credits
|
124
126
|
|
125
|
-
This is a port of [Sindre Sorhus](https://github.com/sindresorhus) JavaScript's [yn](https://github.com/sindresorhus/yn)
|
126
|
-
|
127
|
+
This is a port of [Sindre Sorhus](https://github.com/sindresorhus) JavaScript's [yn](https://github.com/sindresorhus/yn).
|
128
|
+
I'm a big fan of his work!
|
127
129
|
|
128
130
|
## Code of Conduct
|
129
131
|
|
data/lib/yn.rb
CHANGED
@@ -3,6 +3,52 @@ require 'yn/lenient'
|
|
3
3
|
|
4
4
|
# Encapsulates all the code of the gem in a meaningful namespace.
|
5
5
|
module Yn
|
6
|
+
# Parses yes/no like values
|
7
|
+
#
|
8
|
+
# @example Parsing yes-like values
|
9
|
+
# Yn.parse('y') # => true
|
10
|
+
# Yn.parse('yes') # => true
|
11
|
+
# Yn.parse('Yes') # => true
|
12
|
+
# Yn.parse('YES') # => true
|
13
|
+
# Yn.parse('1') # => true
|
14
|
+
# Yn.parse(1) # => true
|
15
|
+
# Yn.parse('on') # => true
|
16
|
+
# Yn.parse('true') # => true
|
17
|
+
# Yn.parse(true) # => true
|
18
|
+
#
|
19
|
+
# @example Parsing no-like values
|
20
|
+
# Yn.parse('n') # => false
|
21
|
+
# Yn.parse('no') # => false
|
22
|
+
# Yn.parse('No') # => false
|
23
|
+
# Yn.parse('NO') # => false
|
24
|
+
# Yn.parse('0') # => false
|
25
|
+
# Yn.parse(0) # => false
|
26
|
+
# Yn.parse('off') # => false
|
27
|
+
# Yn.parse('false') # => false
|
28
|
+
# Yn.parse(false) # => false
|
29
|
+
#
|
30
|
+
# @example Allowing typos in the words yes or no
|
31
|
+
# Yn.parse('y7s', lenient: true) # => true
|
32
|
+
# Yn.parse('tes', lenient: true) # => true
|
33
|
+
# Yn.parse('yes', lenient: true) # => true
|
34
|
+
# Yn.parse('mo', lenient: true) # => false
|
35
|
+
# Yn.parse('nl', lenient: true) # => false
|
36
|
+
# Yn.parse('no', lenient: true) # => false
|
37
|
+
# Yn.parse('something-else', lenient: true) # => nil
|
38
|
+
#
|
39
|
+
# @example Using a default value
|
40
|
+
# Yn.parse('falso', default: false) # => false
|
41
|
+
# Yn.parse('verdadeiro', default: true) # => true
|
42
|
+
#
|
43
|
+
# @param [Object] input The input object or string to be converted
|
44
|
+
# @param [Object] lenient Whether typos in words +yes+ and +no+ are allowed or not
|
45
|
+
# @param [Object] default Value returned when the +input+ isn't considered +yes+ or +no+
|
46
|
+
#
|
47
|
+
# @return [Boolean|nil] +true+ if the input is a yes-like value, +false+ if the input is a no-like value
|
48
|
+
# and +nil+ or +default+ otherwise.
|
49
|
+
#
|
50
|
+
# @api public
|
51
|
+
#
|
6
52
|
def self.parse(input, lenient: false, default: nil)
|
7
53
|
input = input.to_s.strip
|
8
54
|
|
data/lib/yn/lenient.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Encapsulates all the code of the gem in a meaningful namespace.
|
2
2
|
module Yn
|
3
|
-
#
|
3
|
+
# Gracefully handles typos in the words +yes+ or +no+.
|
4
4
|
class Lenient
|
5
5
|
YES_MATCH_SCORE_THRESHOLD = 2
|
6
6
|
NO_MATCH_SCORE_THRESHOLD = 1.25
|
@@ -60,6 +60,16 @@ module Yn
|
|
60
60
|
['l', 0.25]
|
61
61
|
].to_h
|
62
62
|
|
63
|
+
# Returns +true+ or +false+ if input resembles the words +yes+ or +no+ respectively,
|
64
|
+
# or the given +default+ otherwise
|
65
|
+
#
|
66
|
+
# @param [String] input The string to compare with the words +yes+ or +no+
|
67
|
+
# @param [Object] default Value returned when the +input+ doesn't resemble the words +yes+ or +no+
|
68
|
+
#
|
69
|
+
# @return [Object]
|
70
|
+
#
|
71
|
+
# @api private
|
72
|
+
#
|
63
73
|
def call(input, default)
|
64
74
|
return true if get_yes_match_score(input) >= YES_MATCH_SCORE_THRESHOLD
|
65
75
|
return false if get_no_match_score(input) >= NO_MATCH_SCORE_THRESHOLD
|
@@ -69,6 +79,14 @@ module Yn
|
|
69
79
|
|
70
80
|
private
|
71
81
|
|
82
|
+
# Returns a match score with word +yes+ between 0 and 3
|
83
|
+
#
|
84
|
+
# @param [String] input The string to compare with the word +yes+
|
85
|
+
#
|
86
|
+
# @return [Fixnum|Float]
|
87
|
+
#
|
88
|
+
# @api private
|
89
|
+
#
|
72
90
|
def get_yes_match_score(input)
|
73
91
|
y, e, s = input.split('')
|
74
92
|
|
@@ -79,6 +97,14 @@ module Yn
|
|
79
97
|
score
|
80
98
|
end
|
81
99
|
|
100
|
+
# Returns a match score with word +no+ between 0 and 2
|
101
|
+
#
|
102
|
+
# @param [String] input The string to compare with the word +no+
|
103
|
+
#
|
104
|
+
# @return [Fixnum|Float]
|
105
|
+
#
|
106
|
+
# @api private
|
107
|
+
#
|
82
108
|
def get_no_match_score(input)
|
83
109
|
n, o = input.split('')
|
84
110
|
|
data/lib/yn/version.rb
CHANGED
data/yn.gemspec
CHANGED
@@ -18,6 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.metadata['source_code_uri'] = 'https://github.com/wilsonsilva/yn'
|
19
19
|
spec.metadata['changelog_uri'] = 'https://github.com/wilsonsilva/yn/blob/master/CHANGELOG.md'
|
20
20
|
|
21
|
+
spec.required_ruby_version = '>= 2.3'
|
22
|
+
|
21
23
|
# Specify which files should be added to the gem when it is released.
|
22
24
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
25
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yn
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wilson Silva
|
@@ -305,7 +305,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
305
305
|
requirements:
|
306
306
|
- - ">="
|
307
307
|
- !ruby/object:Gem::Version
|
308
|
-
version: '
|
308
|
+
version: '2.3'
|
309
309
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
310
310
|
requirements:
|
311
311
|
- - ">="
|