duck_puncher 2.14.0 → 2.14.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7fe012dba97c4da38fb5bc38059198edbcc660d2
4
- data.tar.gz: 082403f80db3693547ccb17d37fd136dbc5bec77
3
+ metadata.gz: ed2243d867622b1a9e14ba912b1fab688146bb34
4
+ data.tar.gz: f85382a4793aee2856111591dd7fb27fbb0ff49d
5
5
  SHA512:
6
- metadata.gz: 3b3f930ba269bcb2994ebe0757c898da76d51f89cec8fb9ffd0b939a0970effdb1b302305c7d90e2711b3dc9ab10b249bbebc576253b35f2e769fef65b46eee2
7
- data.tar.gz: 65092fd347480630b9a4dd5c5e4a5c03e0ec21ce2cfb9171e8ae01147426ae78582ca55ed7bcdbeb2da5e0954261c23adcec403ce65842ceb5d3897fb090d706
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(strict = false)
13
- @boolean_map ||= begin
14
- truths, falsities = %w(true 1 yes y on), ['false', '0', 'no', 'n', 'off', '']
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
@@ -1,3 +1,3 @@
1
1
  module DuckPuncher
2
- VERSION = '2.14.0'.freeze
2
+ VERSION = '2.14.1'.freeze
3
3
  end
@@ -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.0
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-04-09 00:00:00.000000000 Z
11
+ date: 2016-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: usable