to_be 0.0.1
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/LICENSE +31 -0
- data/README.md +127 -0
- data/lib/to_be/extensions/string.rb +34 -0
- data/lib/to_be/internal/_str2bool.rb +73 -0
- data/lib/to_be/truthy.rb +48 -0
- data/lib/to_be/version.rb +70 -0
- data/lib/to_be.rb +12 -0
- data/test/unit/tc_extensions_truthy.rb +97 -0
- data/test/unit/tc_truthy.rb +97 -0
- data/test/unit/tc_version.rb +38 -0
- data/test/unit/ts_all.rb +12 -0
- metadata +74 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7cad135b7c9f7014fe409c78f79db0b17a83245bbaa8fa907cc45b8b8fc3891d
|
4
|
+
data.tar.gz: 8f551d45b01ee0c1cbd6894d61d5d06f9e811689e8803df272d5594a9e5fe716
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b7591524247b3a9701468833511c4afcc5ed1f0a19354e7bbd3797edfdd8ace33b6a7cadad3211cafa7a87cfa6b554eff8fcb255ec8b813042c31a4898c7f44d
|
7
|
+
data.tar.gz: 55e5001d04db602e98f39b8e4ae23f108917a18a719d93538983620a9423782faba0c26f977fee9dc30ad098072f5a4cf163c8e56bd1ac6bf97d6b8f8bedc78f
|
data/LICENSE
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
to_be.Ruby - BSD 3-Clause License
|
2
|
+
|
3
|
+
Copyright (c) 2025, Matthew Wilson and Synesis Information Systems
|
4
|
+
All rights reserved.
|
5
|
+
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
8
|
+
|
9
|
+
1. Redistributions of source code must retain the above copyright notice,
|
10
|
+
this list of conditions and the following disclaimer.
|
11
|
+
|
12
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
14
|
+
and/or other materials provided with the distribution.
|
15
|
+
|
16
|
+
3. Neither the name of the copyright holder nor the names of its
|
17
|
+
contributors may be used to endorse or promote products derived from
|
18
|
+
this software without specific prior written permission.
|
19
|
+
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
21
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
22
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
23
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
24
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
25
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
26
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
27
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
28
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
29
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
30
|
+
POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
|
data/README.md
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
# to_be.Ruby <!-- omit in toc -->
|
2
|
+
|
3
|
+
Simple Ruby library determining whether strings indicate truey or falsy values.
|
4
|
+
|
5
|
+
[](https://badge.fury.io/rb/to_be)
|
6
|
+
|
7
|
+
|
8
|
+
## Introduction
|
9
|
+
|
10
|
+
**to-be** is a library providing facilities for determine whether the truthyness of strings. It implemented in several languages: **to_be.Rust** is the **Ruby** implementation.
|
11
|
+
|
12
|
+
|
13
|
+
## Table of Contents <!-- omit in toc -->
|
14
|
+
|
15
|
+
- [Introduction](#introduction)
|
16
|
+
- [Terminology](#terminology)
|
17
|
+
- [Installation](#installation)
|
18
|
+
- [Project Information](#project-information)
|
19
|
+
- [Where to get help](#where-to-get-help)
|
20
|
+
- [Contribution guidelines](#contribution-guidelines)
|
21
|
+
- [Related projects](#related-projects)
|
22
|
+
- [License](#license)
|
23
|
+
|
24
|
+
|
25
|
+
## Terminology
|
26
|
+
|
27
|
+
The term "*truthy*" is an unhelpfully overloaded term in the programming world, insofar as it is used to refer to the notion of "truthyness" - whether something can be _deemed to be_ interpretable as truth - and also the true side of that interpretation. In this library, the former interpretation is used, leaving us with the following terms:
|
28
|
+
|
29
|
+
* "*truthy*" - whether something can be can be _deemed to be_ interpretable as having truth;
|
30
|
+
* "*falsey*" - whether an object can be _deemed to be_ interpretable as being false;
|
31
|
+
* "*truey*" - whether an object can be _deemed to be_ interpretable as being true;
|
32
|
+
|
33
|
+
For example, consider the following **Ruby** program:
|
34
|
+
|
35
|
+
```Ruby
|
36
|
+
require 'to_be'
|
37
|
+
|
38
|
+
s1 = "no"
|
39
|
+
s2 = "True"
|
40
|
+
s3 = "orange"
|
41
|
+
|
42
|
+
# "no" is validly truthy, and is falsey
|
43
|
+
ToBe.string_falsey?(s1) # => true
|
44
|
+
ToBe.string_truey?(s1) # => false
|
45
|
+
ToBe.string_truthy?(s1) # => true
|
46
|
+
|
47
|
+
# "True" is validly truthy, and is truey
|
48
|
+
ToBe.string_falsey?(s2) # => false
|
49
|
+
ToBe.string_truey?(s2) # => true
|
50
|
+
ToBe.string_truthy?(s2) # => true
|
51
|
+
|
52
|
+
# "orange" is not validly truthy, and is neither falsey nor truey
|
53
|
+
ToBe.string_falsey?(s3) # => false
|
54
|
+
ToBe.string_truey?(s3) # => false
|
55
|
+
ToBe.string_truthy?(s3) # => false
|
56
|
+
```
|
57
|
+
|
58
|
+
and, if extensions are used, the following **Ruby** program:
|
59
|
+
|
60
|
+
```Ruby
|
61
|
+
require 'to_be/extensions/string'
|
62
|
+
|
63
|
+
s1 = "no"
|
64
|
+
s2 = "True"
|
65
|
+
s3 = "orange"
|
66
|
+
|
67
|
+
# "no" is validly truthy, and is falsey
|
68
|
+
s1.falsey? # => true
|
69
|
+
s1.truey? # => false
|
70
|
+
s1.truthy? # => true
|
71
|
+
|
72
|
+
# "True" is validly truthy, and is truey
|
73
|
+
s2.falsey? # => false
|
74
|
+
s2.truey? # => true
|
75
|
+
s2.truthy? # => true
|
76
|
+
|
77
|
+
# "orange" is not validly truthy, and is neither falsey nor truey
|
78
|
+
s3.falsey? # => false
|
79
|
+
s3.truey? # => false
|
80
|
+
s3.truthy? # => false
|
81
|
+
```
|
82
|
+
|
83
|
+
|
84
|
+
## Installation
|
85
|
+
|
86
|
+
Install via **gem** as in:
|
87
|
+
|
88
|
+
```
|
89
|
+
gem install to_be
|
90
|
+
```
|
91
|
+
|
92
|
+
or add it to your `Gemfile`.
|
93
|
+
|
94
|
+
Use via **require**, as in:
|
95
|
+
|
96
|
+
```Ruby
|
97
|
+
require 'to_be'
|
98
|
+
```
|
99
|
+
|
100
|
+
|
101
|
+
## Project Information
|
102
|
+
|
103
|
+
|
104
|
+
### Where to get help
|
105
|
+
|
106
|
+
[GitHub Page](https://github.com/synesissoftware/to_be.Ruby "GitHub Page")
|
107
|
+
|
108
|
+
|
109
|
+
### Contribution guidelines
|
110
|
+
|
111
|
+
Defect reports, feature requests, and pull requests are welcome on https://github.com/synesissoftware/to_be.Ruby.
|
112
|
+
|
113
|
+
|
114
|
+
### Related projects
|
115
|
+
|
116
|
+
* [**to-be**](https://github.com/synesissoftware/to-be) (**C**);
|
117
|
+
* [**py2be**](https://github.com/synesissoftware/py2be) (**Python**);
|
118
|
+
* [**to-be.Rust**](https://github.com/synesissoftware/to-be.Rust);
|
119
|
+
|
120
|
+
|
121
|
+
### License
|
122
|
+
|
123
|
+
**to_be.Ruby** is released under the 3-clause BSD license. See LICENSE for details.
|
124
|
+
|
125
|
+
|
126
|
+
<!-- ########################### end of file ########################### -->
|
127
|
+
|
@@ -0,0 +1,34 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
require 'to_be/truthy'
|
4
|
+
|
5
|
+
class String
|
6
|
+
|
7
|
+
# Indicates that the instance, when trimmed, is classified as "truthy" and
|
8
|
+
# is deemed as "falsey".
|
9
|
+
#
|
10
|
+
# See ToBe::string_falsey?
|
11
|
+
def falsey?
|
12
|
+
|
13
|
+
return ToBe::string_falsey? self
|
14
|
+
end
|
15
|
+
|
16
|
+
# Indicates that the instance, when trimmed, is classified as "truthy" and
|
17
|
+
# is deemed as "falsey".
|
18
|
+
#
|
19
|
+
# See ToBe::string_truey?
|
20
|
+
def truey?
|
21
|
+
|
22
|
+
return ToBe::string_truey? self
|
23
|
+
end
|
24
|
+
|
25
|
+
# Indicates that the instances, when trimmed, is classified as "truthy"
|
26
|
+
# (and is deemed as either "falsey" or "truey").
|
27
|
+
#
|
28
|
+
# See ToBe::string_truthy?
|
29
|
+
def truthy?
|
30
|
+
|
31
|
+
return ToBe::string_truthy? self
|
32
|
+
end
|
33
|
+
end # class String
|
34
|
+
|
@@ -0,0 +1,73 @@
|
|
1
|
+
|
2
|
+
=begin
|
3
|
+
=end
|
4
|
+
|
5
|
+
module ToBe
|
6
|
+
module Internal
|
7
|
+
|
8
|
+
module Constants_
|
9
|
+
|
10
|
+
FALSEY_PRECISE_STRINGS = [
|
11
|
+
"0",
|
12
|
+
"FALSE",
|
13
|
+
"False",
|
14
|
+
"NO",
|
15
|
+
"No",
|
16
|
+
"OFF",
|
17
|
+
"Off",
|
18
|
+
"false",
|
19
|
+
"no",
|
20
|
+
"off",
|
21
|
+
]
|
22
|
+
|
23
|
+
TRUEY_PRECISE_STRINGS = [
|
24
|
+
"1",
|
25
|
+
"ON",
|
26
|
+
"On",
|
27
|
+
"TRUE",
|
28
|
+
"True",
|
29
|
+
"YES",
|
30
|
+
"Yes",
|
31
|
+
"on",
|
32
|
+
"true",
|
33
|
+
"yes",
|
34
|
+
]
|
35
|
+
|
36
|
+
FALSEY_LOWERCASE_STRINGS = [
|
37
|
+
"false",
|
38
|
+
"no",
|
39
|
+
"off",
|
40
|
+
"0",
|
41
|
+
]
|
42
|
+
|
43
|
+
TRUEY_LOWERCASE_STRINGS = [
|
44
|
+
"true",
|
45
|
+
"yes",
|
46
|
+
"on",
|
47
|
+
"1",
|
48
|
+
]
|
49
|
+
|
50
|
+
end # module Constants_
|
51
|
+
|
52
|
+
def self._str2bool s
|
53
|
+
|
54
|
+
return nil if s.nil?
|
55
|
+
|
56
|
+
return true if Constants_::TRUEY_PRECISE_STRINGS.include? s
|
57
|
+
|
58
|
+
return false if Constants_::FALSEY_PRECISE_STRINGS.include? s
|
59
|
+
|
60
|
+
s = s.strip.downcase
|
61
|
+
|
62
|
+
return true if Constants_::TRUEY_LOWERCASE_STRINGS.include? s
|
63
|
+
|
64
|
+
return false if Constants_::FALSEY_LOWERCASE_STRINGS.include? s
|
65
|
+
|
66
|
+
nil
|
67
|
+
end
|
68
|
+
end # module Internal
|
69
|
+
end # module ToBe
|
70
|
+
|
71
|
+
|
72
|
+
# ############################## end of file ############################# #
|
73
|
+
|
data/lib/to_be/truthy.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
require 'to_be/internal/_str2bool'
|
4
|
+
|
5
|
+
=begin
|
6
|
+
=end
|
7
|
+
|
8
|
+
module ToBe
|
9
|
+
|
10
|
+
# Determines the "truthy" nature of whether the given string is "truthy"
|
11
|
+
# and, if so, whether it is "falsey" or "truey".
|
12
|
+
#
|
13
|
+
# Returns:
|
14
|
+
# - `None` - string is not classified as "truthy";
|
15
|
+
# - `False` - string is classified as "truthy" and is deemed "falsey";
|
16
|
+
# - `True` - string is classified as "truthy" and is deemed "truey";
|
17
|
+
def str2bool s
|
18
|
+
|
19
|
+
ToBe::Internal::_str2bool s
|
20
|
+
end
|
21
|
+
|
22
|
+
# Indicates that the given string, when trimmed, is classified as "truthy"
|
23
|
+
# and is deemed as "falsey".
|
24
|
+
def string_falsey? s
|
25
|
+
|
26
|
+
return false == ToBe::Internal::_str2bool(s)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Indicates that the given string, when trimmed, is classified as "truthy"
|
30
|
+
# and is deemed as "truey".
|
31
|
+
def string_truey? s
|
32
|
+
|
33
|
+
return true == ToBe::Internal::_str2bool(s)
|
34
|
+
end
|
35
|
+
|
36
|
+
# Indicates that the given string, when trimmed, is classified as "truthy"
|
37
|
+
# (and is deemed as either "falsey" or "truey").
|
38
|
+
def string_truthy? s
|
39
|
+
|
40
|
+
return !ToBe::Internal::_str2bool(s).nil?
|
41
|
+
end
|
42
|
+
|
43
|
+
module_function :string_falsey?, :string_truey?, :string_truthy?
|
44
|
+
end # module ToBe
|
45
|
+
|
46
|
+
|
47
|
+
# ############################## end of file ############################# #
|
48
|
+
|
@@ -0,0 +1,70 @@
|
|
1
|
+
|
2
|
+
# ######################################################################## #
|
3
|
+
# File: to_be/version.rb
|
4
|
+
#
|
5
|
+
# Purpose: Version for ToBe.Ruby library
|
6
|
+
#
|
7
|
+
# Created: 11th August 2025
|
8
|
+
# Updated: 11th August 2025
|
9
|
+
#
|
10
|
+
# Home: http://github.com/synesissoftware/to_be.Ruby
|
11
|
+
#
|
12
|
+
# Author: Matthew Wilson
|
13
|
+
#
|
14
|
+
# Copyright (c) 2025, Matthew Wilson and Synesis Information Systems
|
15
|
+
# All rights reserved.
|
16
|
+
#
|
17
|
+
# Redistribution and use in source and binary forms, with or without
|
18
|
+
# modification, are permitted provided that the following conditions are
|
19
|
+
# met:
|
20
|
+
#
|
21
|
+
# * Redistributions of source code must retain the above copyright
|
22
|
+
# notice, this list of conditions and the following disclaimer.
|
23
|
+
#
|
24
|
+
# * Redistributions in binary form must reproduce the above copyright
|
25
|
+
# notice, this list of conditions and the following disclaimer in the
|
26
|
+
# documentation and/or other materials provided with the distribution.
|
27
|
+
#
|
28
|
+
# * Neither the names of the copyright holder nor the names of its
|
29
|
+
# contributors may be used to endorse or promote products derived from
|
30
|
+
# this software without specific prior written permission.
|
31
|
+
#
|
32
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
33
|
+
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
34
|
+
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
35
|
+
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
36
|
+
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
37
|
+
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
38
|
+
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
39
|
+
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
40
|
+
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
41
|
+
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
42
|
+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
43
|
+
#
|
44
|
+
# ######################################################################## #
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
=begin
|
49
|
+
=end
|
50
|
+
|
51
|
+
module ToBe
|
52
|
+
|
53
|
+
# Current version of the ToBe.Ruby library
|
54
|
+
VERSION = '0.0.1'
|
55
|
+
|
56
|
+
private
|
57
|
+
# @!visibility private
|
58
|
+
VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
|
59
|
+
public
|
60
|
+
# Major version of the ToBe.Ruby library
|
61
|
+
VERSION_MAJOR = VERSION_PARTS_[0] # :nodoc:
|
62
|
+
# Minor version of the ToBe.Ruby library
|
63
|
+
VERSION_MINOR = VERSION_PARTS_[1] # :nodoc:
|
64
|
+
# Revision version of the ToBe.Ruby library
|
65
|
+
VERSION_REVISION = VERSION_PARTS_[2] # :nodoc:
|
66
|
+
end # module ToBe
|
67
|
+
|
68
|
+
|
69
|
+
# ############################## end of file ############################# #
|
70
|
+
|
data/lib/to_be.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), '../..', 'lib')
|
4
|
+
|
5
|
+
require 'to_be/extensions/string'
|
6
|
+
|
7
|
+
require 'xqsr3/extensions/test/unit'
|
8
|
+
require 'test/unit'
|
9
|
+
|
10
|
+
|
11
|
+
class Test_ToBe_EXTENSIONS_String < Test::Unit::TestCase
|
12
|
+
|
13
|
+
def test__string_falsey?()
|
14
|
+
|
15
|
+
assert_false "".falsey?
|
16
|
+
assert_false "Copyright ©".falsey?
|
17
|
+
|
18
|
+
assert_true "0".falsey?
|
19
|
+
assert_true "false".falsey?
|
20
|
+
assert_true " FALSE".falsey?
|
21
|
+
assert_true "False".falsey?
|
22
|
+
assert_true "FaLSe".falsey?
|
23
|
+
assert_true "no".falsey?
|
24
|
+
assert_true "No ".falsey?
|
25
|
+
assert_true "NO".falsey?
|
26
|
+
assert_true " Off ".falsey?
|
27
|
+
assert_true "off".falsey?
|
28
|
+
assert_true "OFF".falsey?
|
29
|
+
|
30
|
+
assert_false "1".falsey?
|
31
|
+
assert_false "true".falsey?
|
32
|
+
assert_false "TRUE".falsey?
|
33
|
+
assert_false "True".falsey?
|
34
|
+
assert_false "tRuE".falsey?
|
35
|
+
assert_false "yes".falsey?
|
36
|
+
assert_false " YES".falsey?
|
37
|
+
assert_false "Yes ".falsey?
|
38
|
+
assert_false "yEs".falsey?
|
39
|
+
end
|
40
|
+
|
41
|
+
def test__string_truey?()
|
42
|
+
|
43
|
+
assert_false "".truey?
|
44
|
+
assert_false "Copyright ©".truey?
|
45
|
+
|
46
|
+
assert_false "0".truey?
|
47
|
+
assert_false "false".truey?
|
48
|
+
assert_false " FALSE".truey?
|
49
|
+
assert_false "False".truey?
|
50
|
+
assert_false "FaLSe".truey?
|
51
|
+
assert_false "no".truey?
|
52
|
+
assert_false "No ".truey?
|
53
|
+
assert_false "NO".truey?
|
54
|
+
assert_false " Off ".truey?
|
55
|
+
assert_false "off".truey?
|
56
|
+
assert_false "OFF".truey?
|
57
|
+
|
58
|
+
assert_true "1".truey?
|
59
|
+
assert_true "true".truey?
|
60
|
+
assert_true "TRUE".truey?
|
61
|
+
assert_true "True".truey?
|
62
|
+
assert_true "tRuE".truey?
|
63
|
+
assert_true "yes".truey?
|
64
|
+
assert_true " YES".truey?
|
65
|
+
assert_true "Yes ".truey?
|
66
|
+
assert_true "yEs".truey?
|
67
|
+
end
|
68
|
+
|
69
|
+
def test__string_truthy?()
|
70
|
+
|
71
|
+
assert_false "".truthy?
|
72
|
+
assert_false "Copyright ©".truthy?
|
73
|
+
|
74
|
+
assert_true "0".truthy?
|
75
|
+
assert_true "false".truthy?
|
76
|
+
assert_true " FALSE".truthy?
|
77
|
+
assert_true "False".truthy?
|
78
|
+
assert_true "FaLSe".truthy?
|
79
|
+
assert_true "no".truthy?
|
80
|
+
assert_true "No ".truthy?
|
81
|
+
assert_true "NO".truthy?
|
82
|
+
assert_true " Off ".truthy?
|
83
|
+
assert_true "off".truthy?
|
84
|
+
assert_true "OFF".truthy?
|
85
|
+
|
86
|
+
assert_true "1".truthy?
|
87
|
+
assert_true "true".truthy?
|
88
|
+
assert_true "TRUE".truthy?
|
89
|
+
assert_true "True".truthy?
|
90
|
+
assert_true "tRuE".truthy?
|
91
|
+
assert_true "yes".truthy?
|
92
|
+
assert_true " YES".truthy?
|
93
|
+
assert_true "Yes ".truthy?
|
94
|
+
assert_true "yEs".truthy?
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
@@ -0,0 +1,97 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), '../..', 'lib')
|
4
|
+
|
5
|
+
require 'to_be'
|
6
|
+
|
7
|
+
require 'xqsr3/extensions/test/unit'
|
8
|
+
require 'test/unit'
|
9
|
+
|
10
|
+
|
11
|
+
class Test_ToBe < Test::Unit::TestCase
|
12
|
+
|
13
|
+
def test__string_falsey?()
|
14
|
+
|
15
|
+
assert_false ToBe.string_falsey?("")
|
16
|
+
assert_false ToBe.string_falsey?("Copyright ©")
|
17
|
+
|
18
|
+
assert_true ToBe.string_falsey?("0")
|
19
|
+
assert_true ToBe.string_falsey?("false")
|
20
|
+
assert_true ToBe.string_falsey?(" FALSE")
|
21
|
+
assert_true ToBe.string_falsey?("False")
|
22
|
+
assert_true ToBe.string_falsey?("FaLSe")
|
23
|
+
assert_true ToBe.string_falsey?("no")
|
24
|
+
assert_true ToBe.string_falsey?("No ")
|
25
|
+
assert_true ToBe.string_falsey?("NO")
|
26
|
+
assert_true ToBe.string_falsey?(" Off ")
|
27
|
+
assert_true ToBe.string_falsey?("off")
|
28
|
+
assert_true ToBe.string_falsey?("OFF")
|
29
|
+
|
30
|
+
assert_false ToBe.string_falsey?("1")
|
31
|
+
assert_false ToBe.string_falsey?("true")
|
32
|
+
assert_false ToBe.string_falsey?("TRUE")
|
33
|
+
assert_false ToBe.string_falsey?("True")
|
34
|
+
assert_false ToBe.string_falsey?("tRuE")
|
35
|
+
assert_false ToBe.string_falsey?("yes")
|
36
|
+
assert_false ToBe.string_falsey?(" YES")
|
37
|
+
assert_false ToBe.string_falsey?("Yes ")
|
38
|
+
assert_false ToBe.string_falsey?("yEs")
|
39
|
+
end
|
40
|
+
|
41
|
+
def test__string_truey?()
|
42
|
+
|
43
|
+
assert_false ToBe.string_truey?("")
|
44
|
+
assert_false ToBe.string_truey?("Copyright ©")
|
45
|
+
|
46
|
+
assert_false ToBe.string_truey?("0")
|
47
|
+
assert_false ToBe.string_truey?("false")
|
48
|
+
assert_false ToBe.string_truey?(" FALSE")
|
49
|
+
assert_false ToBe.string_truey?("False")
|
50
|
+
assert_false ToBe.string_truey?("FaLSe")
|
51
|
+
assert_false ToBe.string_truey?("no")
|
52
|
+
assert_false ToBe.string_truey?("No ")
|
53
|
+
assert_false ToBe.string_truey?("NO")
|
54
|
+
assert_false ToBe.string_truey?(" Off ")
|
55
|
+
assert_false ToBe.string_truey?("off")
|
56
|
+
assert_false ToBe.string_truey?("OFF")
|
57
|
+
|
58
|
+
assert_true ToBe.string_truey?("1")
|
59
|
+
assert_true ToBe.string_truey?("true")
|
60
|
+
assert_true ToBe.string_truey?("TRUE")
|
61
|
+
assert_true ToBe.string_truey?("True")
|
62
|
+
assert_true ToBe.string_truey?("tRuE")
|
63
|
+
assert_true ToBe.string_truey?("yes")
|
64
|
+
assert_true ToBe.string_truey?(" YES")
|
65
|
+
assert_true ToBe.string_truey?("Yes ")
|
66
|
+
assert_true ToBe.string_truey?("yEs")
|
67
|
+
end
|
68
|
+
|
69
|
+
def test__string_truthy?()
|
70
|
+
|
71
|
+
assert_false ToBe.string_truthy?("")
|
72
|
+
assert_false ToBe.string_truthy?("Copyright ©")
|
73
|
+
|
74
|
+
assert_true ToBe.string_truthy?("0")
|
75
|
+
assert_true ToBe.string_truthy?("false")
|
76
|
+
assert_true ToBe.string_truthy?(" FALSE")
|
77
|
+
assert_true ToBe.string_truthy?("False")
|
78
|
+
assert_true ToBe.string_truthy?("FaLSe")
|
79
|
+
assert_true ToBe.string_truthy?("no")
|
80
|
+
assert_true ToBe.string_truthy?("No ")
|
81
|
+
assert_true ToBe.string_truthy?("NO")
|
82
|
+
assert_true ToBe.string_truthy?(" Off ")
|
83
|
+
assert_true ToBe.string_truthy?("off")
|
84
|
+
assert_true ToBe.string_truthy?("OFF")
|
85
|
+
|
86
|
+
assert_true ToBe.string_truthy?("1")
|
87
|
+
assert_true ToBe.string_truthy?("true")
|
88
|
+
assert_true ToBe.string_truthy?("TRUE")
|
89
|
+
assert_true ToBe.string_truthy?("True")
|
90
|
+
assert_true ToBe.string_truthy?("tRuE")
|
91
|
+
assert_true ToBe.string_truthy?("yes")
|
92
|
+
assert_true ToBe.string_truthy?(" YES")
|
93
|
+
assert_true ToBe.string_truthy?("Yes ")
|
94
|
+
assert_true ToBe.string_truthy?("yEs")
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
$:.unshift File.join(File.dirname(__FILE__), '../../lib')
|
4
|
+
|
5
|
+
|
6
|
+
require 'to_be/version'
|
7
|
+
|
8
|
+
require 'test/unit'
|
9
|
+
|
10
|
+
|
11
|
+
class Test_version < Test::Unit::TestCase
|
12
|
+
|
13
|
+
def test_has_VERSION
|
14
|
+
|
15
|
+
assert defined? ToBe::VERSION
|
16
|
+
end
|
17
|
+
|
18
|
+
def test_has_VERSION_MAJOR
|
19
|
+
|
20
|
+
assert defined? ToBe::VERSION_MAJOR
|
21
|
+
end
|
22
|
+
|
23
|
+
def test_has_VERSION_MINOR
|
24
|
+
|
25
|
+
assert defined? ToBe::VERSION_MINOR
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_has_VERSION_REVISION
|
29
|
+
|
30
|
+
assert defined? ToBe::VERSION_REVISION
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_VERSION_has_consistent_format
|
34
|
+
|
35
|
+
assert_equal ToBe::VERSION.split('.')[0..2].join('.'), "#{ToBe::VERSION_MAJOR}.#{ToBe::VERSION_MINOR}.#{ToBe::VERSION_REVISION}"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
data/test/unit/ts_all.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# executes all other tests
|
4
|
+
|
5
|
+
this_dir = File.expand_path(File.dirname(__FILE__))
|
6
|
+
|
7
|
+
# all tc_*rb in current directory
|
8
|
+
Dir[File.join(this_dir, 'tc_*rb')].each { |file| require file }
|
9
|
+
|
10
|
+
# all ts_*rb in immediate sub-directories
|
11
|
+
Dir[File.join(this_dir, '*', 'ts_*rb')].each { |file| require file }
|
12
|
+
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: to_be
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matt Wilson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-08-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: xqsr3
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.38'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.38'
|
27
|
+
description: 'Simple Ruby library determining whether strings indicate truey or falsy
|
28
|
+
values.
|
29
|
+
|
30
|
+
'
|
31
|
+
email: matthew@synesis.com.au
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- LICENSE
|
37
|
+
- README.md
|
38
|
+
- lib/to_be.rb
|
39
|
+
- lib/to_be/extensions/string.rb
|
40
|
+
- lib/to_be/internal/_str2bool.rb
|
41
|
+
- lib/to_be/truthy.rb
|
42
|
+
- lib/to_be/version.rb
|
43
|
+
- test/unit/tc_extensions_truthy.rb
|
44
|
+
- test/unit/tc_truthy.rb
|
45
|
+
- test/unit/tc_version.rb
|
46
|
+
- test/unit/ts_all.rb
|
47
|
+
homepage: http://github.com/synesissoftware/to_be.Ruby
|
48
|
+
licenses:
|
49
|
+
- BSD-3-Clause
|
50
|
+
metadata: {}
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 1.9.3
|
60
|
+
- - "<"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '4'
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
requirements: []
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 2.7.6.3
|
71
|
+
signing_key:
|
72
|
+
specification_version: 4
|
73
|
+
summary: to_be
|
74
|
+
test_files: []
|