duck_puncher 2.14.0 → 2.14.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 +4 -4
- data/README.md +1 -0
- data/lib/duck_puncher/ducks/string.rb +5 -7
- data/lib/duck_puncher/version.rb +1 -1
- data/test/lib/duck_puncher/string_test.rb +14 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed2243d867622b1a9e14ba912b1fab688146bb34
|
4
|
+
data.tar.gz: f85382a4793aee2856111591dd7fb27fbb0ff49d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e01eec3c27d9bfad7dcaf87714fe341da10f793d783a87c85fefedd49e4398477bb8778023bf0e5ee6f14ccebca77ee687188c9e358a33223aee624c8f344e2d
|
7
|
+
data.tar.gz: 37f5f38e1726065f0f9ae9bcfa8f37877575fc89136fef8ba9bd5e9fda496a6ee46129f9498d94da1918d3b493aa5dd5728d33e168ee13f0fd43c0f81690f534
|
data/README.md
CHANGED
@@ -20,6 +20,7 @@ Numeric #to_currency => `25.245.to_currency` => 25.25
|
|
20
20
|
#to_rad => `10.15.to_rad` => 0.17715091907742445
|
21
21
|
String #pluralize => `'hour'.pluralize(2)` => "hours"
|
22
22
|
#underscore => `'DuckPuncher::JSONStorage'.underscore` => 'duck_puncher/json_storage'
|
23
|
+
#to_boolean => `'1'.to_boolean` => true
|
23
24
|
Object #clone! => `Object.new.clone!` => a deep clone of the object (using Marshal.dump)
|
24
25
|
#punch => `'duck'.punch` => a copy of 'duck' with String punches mixed in
|
25
26
|
Method #to_instruct => `Benchmark.method(:measure).to_instruct` returns the Ruby VM instruction sequence for the method
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module DuckPuncher
|
2
2
|
module Ducks
|
3
3
|
module String
|
4
|
+
BOOLEAN_MAP = ::Hash[%w(true 1 yes y on).product([true]) + ['false', '0', 'no', 'n', 'off', ''].product([false])].freeze
|
5
|
+
|
4
6
|
def pluralize(count)
|
5
7
|
"#{self}#{'s' if count != 1}"
|
6
8
|
end unless method_defined?(:pluralize)
|
@@ -9,13 +11,9 @@ module DuckPuncher
|
|
9
11
|
gsub(/\B([A-Z])([a-z_0-9])/, '_\1\2').gsub('::', '/').downcase
|
10
12
|
end unless method_defined?(:underscore)
|
11
13
|
|
12
|
-
def to_boolean
|
13
|
-
|
14
|
-
|
15
|
-
::Hash[truths.product([true]) + falsities.product([false])]
|
16
|
-
end
|
17
|
-
strict ? !downcase.in?(falsities) : !!@boolean_map[downcase]
|
18
|
-
end
|
14
|
+
def to_boolean
|
15
|
+
!!BOOLEAN_MAP[downcase]
|
16
|
+
end unless method_defined?(:to_boolean)
|
19
17
|
end
|
20
18
|
end
|
21
19
|
end
|
data/lib/duck_puncher/version.rb
CHANGED
@@ -17,4 +17,18 @@ class StringTest < MiniTest::Test
|
|
17
17
|
assert_equal 'mini_test.rb', 'mini_test.rb'.underscore
|
18
18
|
assert_equal 'duck_puncher/json_storage', 'DuckPuncher::JSONStorage'.underscore
|
19
19
|
end
|
20
|
+
|
21
|
+
def test_to_boolean
|
22
|
+
assert 'true'.to_boolean
|
23
|
+
assert '1'.to_boolean
|
24
|
+
assert 'y'.to_boolean
|
25
|
+
assert 'on'.to_boolean
|
26
|
+
assert 'yes'.to_boolean
|
27
|
+
refute 'false'.to_boolean
|
28
|
+
refute '0'.to_boolean
|
29
|
+
refute 'no'.to_boolean
|
30
|
+
refute 'off'.to_boolean
|
31
|
+
refute ''.to_boolean
|
32
|
+
refute 'asd'.to_boolean
|
33
|
+
end
|
20
34
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: duck_puncher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.14.
|
4
|
+
version: 2.14.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Buckley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: usable
|