utilise 0.4.0.pre.27 → 0.4.0.pre.29
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 +8 -8
- data/README.md +5 -5
- data/lib/utilise/augment/bool.rb +11 -11
- data/lib/utilise/augment/matchers.rb +5 -1
- data/lib/utilise/augment/time.rb +2 -1
- data/lib/utilise/augment.rb +7 -0
- data/lib/utilise/version.rb +3 -2
- data/spec/augment/object_spec.rb +9 -9
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MTdlZWEzMGYyZmJmMDU0M2I1YzZiOGY2M2Q2MWUyNjEzOTZjYTBkYg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZWZhZTkzMThkNzZlMzIxMTFkYzcyNzM2YmUwNzMyOTY1NGY2YWU3MQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NjNjMmRhZWZlY2I2NmVlNjQ4ZmQzYmEzY2MyNzVhNWJmM2VjNGZkZGNkZDlm
|
10
|
+
ZGEzOTVlYmQ3NDY3YjNjMDEyNTM4ZjYyZjdhYTAzZDliMDEzNDQxODUwMzNk
|
11
|
+
YzAzZWU5ZmZkZTg3NzQwMzdjMzQ0NTkyNWY5ZTYwNWIyZDAwMWU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YTEzNzM1NjY1NGI4NjYzODUxYjI0Y2QxZTFhYmE4NDRjNWFlNzJkZGMwYTlm
|
14
|
+
NTE4ZTMyMWQzNzMxZmVjOTY2N2VjMGFiZGQyZWNmYjcyMWE5MzU2YTZjODE5
|
15
|
+
Y2I1NWYzNWExOGNiODIwZGFlZTQ1ZjM4ZjNjMmM1NDQwMWQ5N2Y=
|
data/README.md
CHANGED
data/lib/utilise/augment/bool.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
module Utilise
|
2
2
|
module Augment
|
3
|
+
# Extends classes that could be treated as a boolean
|
3
4
|
module Bool
|
4
|
-
|
5
5
|
# Returns bool based on object passed
|
6
6
|
#
|
7
7
|
# @param object [Object] the object
|
8
8
|
# @return [Object] returns object boolean
|
9
|
-
def to_bool
|
9
|
+
def to_bool(object = self)
|
10
10
|
case object
|
11
11
|
when String, Fixnum, Symbol
|
12
12
|
bool_it object
|
@@ -21,10 +21,10 @@ module Utilise
|
|
21
21
|
# value to a boolean if it matches rules
|
22
22
|
#
|
23
23
|
# @param hash [Hash] the hash
|
24
|
-
def bool_hash
|
25
|
-
hash.each do |
|
26
|
-
val = to_bool(
|
27
|
-
hash[
|
24
|
+
def bool_hash(hash)
|
25
|
+
hash.each do |key, val|
|
26
|
+
val = to_bool(val)
|
27
|
+
hash[key] = val unless val.nil?
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -32,10 +32,10 @@ module Utilise
|
|
32
32
|
# element to a boolean if it matches rules
|
33
33
|
#
|
34
34
|
# @param array [Array] the array
|
35
|
-
def bool_array
|
36
|
-
array.each_index do |
|
37
|
-
val = to_bool(array[
|
38
|
-
array[
|
35
|
+
def bool_array(array)
|
36
|
+
array.each_index do |index|
|
37
|
+
val = to_bool(array[index])
|
38
|
+
array[index] = val unless val.nil?
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -43,7 +43,7 @@ module Utilise
|
|
43
43
|
#
|
44
44
|
# @param array [Array] the array
|
45
45
|
# @returns [Boolean] true/false returned
|
46
|
-
def bool_it
|
46
|
+
def bool_it(object)
|
47
47
|
case object.to_s
|
48
48
|
when /^true$/i, /^yes$/i, /^t$/i, /^1$/i
|
49
49
|
true
|
@@ -1,9 +1,13 @@
|
|
1
1
|
module Utilise
|
2
2
|
module Augment
|
3
|
+
# Extends classes that could be queried as a boolean
|
3
4
|
module Matchers
|
4
|
-
def
|
5
|
+
def bool?
|
5
6
|
self.is_a?(TrueClass) || self.is_a?(FalseClass)
|
6
7
|
end
|
8
|
+
|
9
|
+
# NOTE: This keeps backwards compatability
|
10
|
+
alias_method :is_bool?, :bool?
|
7
11
|
end
|
8
12
|
end
|
9
13
|
end
|
data/lib/utilise/augment/time.rb
CHANGED
data/lib/utilise/augment.rb
CHANGED
@@ -2,30 +2,37 @@ require 'utilise/augment/bool.rb'
|
|
2
2
|
require 'utilise/augment/matchers.rb'
|
3
3
|
require 'utilise/augment/time.rb'
|
4
4
|
|
5
|
+
# Extend existing ruby class String
|
5
6
|
class String
|
6
7
|
include Utilise::Augment::Bool
|
7
8
|
end
|
8
9
|
|
10
|
+
# Extend existing ruby class Fixnum
|
9
11
|
class Fixnum
|
10
12
|
include Utilise::Augment::Bool
|
11
13
|
end
|
12
14
|
|
15
|
+
# Extend existing ruby class Symbol
|
13
16
|
class Symbol
|
14
17
|
include Utilise::Augment::Bool
|
15
18
|
end
|
16
19
|
|
20
|
+
# Extend existing ruby class Object
|
17
21
|
class Object
|
18
22
|
include Utilise::Augment::Matchers
|
19
23
|
end
|
20
24
|
|
25
|
+
# Extend existing ruby class Time
|
21
26
|
class Time
|
22
27
|
extend Utilise::Augment::Time
|
23
28
|
end
|
24
29
|
|
30
|
+
# Extend existing ruby class Hash
|
25
31
|
class Hash
|
26
32
|
include Utilise::Augment::Bool
|
27
33
|
end
|
28
34
|
|
35
|
+
# Extend existing ruby class Array
|
29
36
|
class Array
|
30
37
|
include Utilise::Augment::Bool
|
31
38
|
end
|
data/lib/utilise/version.rb
CHANGED
data/spec/augment/object_spec.rb
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
describe TrueClass do
|
4
|
-
describe "#
|
4
|
+
describe "#bool?" do
|
5
5
|
it "returns true when matching" do
|
6
|
-
expect(true.
|
6
|
+
expect(true.bool?).to be true
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
11
|
describe FalseClass do
|
12
|
-
describe "#
|
12
|
+
describe "#bool?" do
|
13
13
|
it "returns true when matching" do
|
14
|
-
expect(false.
|
14
|
+
expect(false.bool?).to be true
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
describe Object do
|
20
|
-
describe "#
|
20
|
+
describe "#bool?" do
|
21
21
|
it "returns false when not matching" do
|
22
|
-
expect("true".
|
23
|
-
expect(0.
|
24
|
-
expect(:false.
|
22
|
+
expect("true".bool?).to be false
|
23
|
+
expect(0.bool?).to be false
|
24
|
+
expect(:false.bool?).to be false
|
25
25
|
end
|
26
26
|
end
|
27
|
-
end
|
27
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: utilise
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.0.pre.
|
4
|
+
version: 0.4.0.pre.29
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Slaughter
|
@@ -56,16 +56,16 @@ dependencies:
|
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ! '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ! '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: '0'
|
69
69
|
description: ! 'Extends a few ruby classes with helpful tools, currently: X.to_bool'
|
70
70
|
email: b.p.slaughter@gmail.com
|
71
71
|
executables: []
|
@@ -113,11 +113,11 @@ signing_key:
|
|
113
113
|
specification_version: 4
|
114
114
|
summary: Utilises a few extra tools
|
115
115
|
test_files:
|
116
|
-
- spec/augment/object_spec.rb
|
117
116
|
- spec/augment/string_spec.rb
|
118
|
-
- spec/augment/symbol_spec.rb
|
119
117
|
- spec/augment/time_spec.rb
|
120
|
-
- spec/augment/
|
118
|
+
- spec/augment/symbol_spec.rb
|
121
119
|
- spec/augment/array_spec.rb
|
120
|
+
- spec/augment/hash_spec.rb
|
122
121
|
- spec/augment/fixnum_spec.rb
|
122
|
+
- spec/augment/object_spec.rb
|
123
123
|
- spec/helper.rb
|