kernel-boolean 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2e081dba1b9e18f6f51eed1a770efbc3a638cb7a7455b8db794375d345300f05
4
+ data.tar.gz: 8e66d7af4c52f092f1a50f5cc6972af5da28054b86607c717c33676cbd6b0e7b
5
+ SHA512:
6
+ metadata.gz: a1fcc4b4ffd4c88ed942feff0685bd78eb4f298ce0dd0ec102982b3e8abe5714cf194748671ef3a01924af0b8f5fcf3dee58fe33774846ab0f9a8f5cfd6a1efb
7
+ data.tar.gz: 6ff29faee0bf807d8d9cf3f2845a18f706cc0be6c4ae742aa3fe5f455d233c66e6637ac86ca786c55e392947ea1c1fa9a6c08f70cff8d542f4b9030e8c80159a
data/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Cyril Kato
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,73 @@
1
+ # `Kernel#Boolean`
2
+
3
+ Returns a boolean based on the given argument.
4
+
5
+ ## Status
6
+
7
+ [![Version](https://img.shields.io/github/v/tag/cyril/kernel-boolean.rb?label=Version&logo=github)](https://github.com/cyril/kernel-boolean.rb/releases)
8
+ [![Yard documentation](https://img.shields.io/badge/Yard-documentation-blue.svg?logo=github)](https://rubydoc.info/github/cyril/kernel-boolean.rb/main)
9
+ [![CI](https://github.com/cyril/kernel-boolean.rb/workflows/CI/badge.svg?branch=main)](https://github.com/cyril/kernel-boolean.rb/actions?query=workflow%3Aci+branch%3Amain)
10
+ [![RuboCop](https://github.com/cyril/kernel-boolean.rb/workflows/RuboCop/badge.svg?branch=main)](https://github.com/cyril/kernel-boolean.rb/actions?query=workflow%3Arubocop+branch%3Amain)
11
+ [![License](https://img.shields.io/github/license/cyril/kernel-boolean.rb?label=License&logo=github)](https://github.com/cyril/kernel-boolean.rb/raw/main/LICENSE.md)
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem "kernel-boolean"
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ ```sh
24
+ bundle
25
+ ```
26
+
27
+ Or install it yourself as:
28
+
29
+ ```sh
30
+ gem install kernel-boolean
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ If the argument is `true`, returns `true`.
36
+ If the argument is `false`, returns `false`.
37
+
38
+ In all other cases, returns an error.
39
+
40
+ ### Example
41
+
42
+ ```ruby
43
+ require "kernel/boolean"
44
+
45
+ Boolean(false) # => false
46
+ Boolean(true) # => true
47
+ Boolean(nil) # => TypeError: can't convert nil into boolean
48
+ Boolean("true") # => ArgumentError: invalid value for Boolean(): "true"
49
+ ```
50
+
51
+ ### Note
52
+
53
+ The `#Boolean` method could be used similarly to the methods already present in the `Kernel` module:
54
+
55
+ * `#Array`
56
+ * `#Complex`
57
+ * `#Float`
58
+ * `#Hash`
59
+ * `#Integer`
60
+ * `#Rational`
61
+ * `#String`
62
+
63
+ ### Warning
64
+
65
+ The `Kernel` module is included in the `Object` class, so by loading this library, the `#Boolean` method will be available in every Ruby object.
66
+
67
+ ## Versioning
68
+
69
+ `Kernel#Boolean` uses [Semantic Versioning 2.0.0](https://semver.org/)
70
+
71
+ ## License
72
+
73
+ The [gem](https://rubygems.org/gems/kernel-boolean) is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The Kernel module.
4
+ module Kernel
5
+ # rubocop:disable Naming/MethodName
6
+
7
+ # @note Converts _arg_ to a boolean. Since a boolean is either `true` or
8
+ # `false`, and `true` and `false` are both a singleton, the `true` value can
9
+ # only be returned if the argument is `true`, and the `false` value can only
10
+ # be returned if the argument is `false`. Therefore, this method can be used
11
+ # to validate that the argument is a boolean.
12
+ #
13
+ # @param arg [#object_id] An object that must be a boolean.
14
+ #
15
+ # @return [Boolean] Either `true` or `false`.
16
+ #
17
+ # @raise [ArgumentError, TypeError] Not conform with boolean representation.
18
+ #
19
+ # @example
20
+ # require "kernel/boolean"
21
+ #
22
+ # Boolean(false) # => false
23
+ # Boolean(true) # => true
24
+ # Boolean(nil) # => TypeError: can't convert nil into boolean
25
+ # Boolean("true") # => ArgumentError: invalid value for Boolean(): "true"
26
+ def Boolean(arg)
27
+ return arg if [false, true].include?(arg)
28
+
29
+ raise ::TypeError, "can't convert nil into boolean" if arg.nil?
30
+
31
+ raise ::ArgumentError, "invalid value for Boolean(): #{arg.inspect}"
32
+ end
33
+ # rubocop:enable Naming/MethodName
34
+ end
data/lib/kernel.rb ADDED
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ # The Kernel module.
4
+ module Kernel
5
+ end
6
+
7
+ require_relative File.join("kernel", "boolean")
metadata ADDED
@@ -0,0 +1,187 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kernel-boolean
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Cyril Kato
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2022-02-24 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: '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: rake
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: r_spec-clone
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: rubocop-md
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: rubocop-performance
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: rubocop-rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-rspec
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: rubocop-thread_safety
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
+ - !ruby/object:Gem::Dependency
126
+ name: simplecov
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: yard
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: Returns a boolean based on the given argument.
154
+ email: contact@cyril.email
155
+ executables: []
156
+ extensions: []
157
+ extra_rdoc_files: []
158
+ files:
159
+ - LICENSE.md
160
+ - README.md
161
+ - lib/kernel.rb
162
+ - lib/kernel/boolean.rb
163
+ homepage: https://github.com/cyril/kernel-boolean.rb
164
+ licenses:
165
+ - MIT
166
+ metadata:
167
+ rubygems_mfa_required: 'true'
168
+ post_install_message:
169
+ rdoc_options: []
170
+ require_paths:
171
+ - lib
172
+ required_ruby_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: 2.7.0
177
+ required_rubygems_version: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ requirements: []
183
+ rubygems_version: 3.1.6
184
+ signing_key:
185
+ specification_version: 4
186
+ summary: Returns a boolean based on the given argument.
187
+ test_files: []