string-present-blank 0.0.2 → 0.0.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 32608198f53b418a69966e5c693f34a20b1ab6a2
4
- data.tar.gz: b53f5b49254bbf9fa4083e2774ef63f8775028cf
3
+ metadata.gz: 12a9f9884b8a55f32c2d73df048ac61af2f8690d
4
+ data.tar.gz: 7ea0bd9dcc876d361720591c3a43c720b741c609
5
5
  SHA512:
6
- metadata.gz: ecc5ede38158c6dc31120ec256674c2e9e2f57effb12ea6fefa3c21c9cbad7f18eb7d03de3e110584d0569f5d4745abd8ca2fe3ceba80f9e5f7ff4e45d1a9d24
7
- data.tar.gz: dc40044e0c654edebf309a908a8ab2df5974da9809772431acd78777f9c10826464d196cdc6ce9f61edd4199fd00a9f8e8b9ff1b5ab3ebbe905863c8ca39418b
6
+ metadata.gz: bb8ead6a2e7dcd5c6c541db3a785669304345359c269874fd9c4ca3edd1736856769e42a1abb32c080bcc79f5d35d96dac6385fe8286eb482cd1ecdfb73ef28f
7
+ data.tar.gz: 0f7746a1e1a5189819b9c93308133a0093a9daa4dc0c64eb6c565fc4b483d5a2b7ee860634131fdc072cbe83da957b949a2870856ac0d707d483eaa03f5bfd1c
@@ -1,11 +1,17 @@
1
1
  module StringPresentBlank
2
2
  module String
3
3
  def present(conditions={})
4
- if_condition = conditions.delete(:if)
5
- if_condition = true if if_condition.nil?
4
+ if_condition = if conditions.has_key?(:if)
5
+ conditions.delete(:if)
6
+ else
7
+ true
8
+ end
6
9
 
7
- unless_condition = conditions.delete(:unless)
8
- unless_condition = false if unless_condition.nil?
10
+ unless_condition = if conditions.has_key?(:unless)
11
+ conditions.delete(:unless)
12
+ else
13
+ false
14
+ end
9
15
 
10
16
  if if_condition and not unless_condition
11
17
  self
@@ -1,3 +1,3 @@
1
1
  module StringPresentBlank
2
- VERSION = '0.0.2'.freeze
2
+ VERSION = '0.0.3'.freeze
3
3
  end
@@ -8,6 +8,8 @@ class TestString < Minitest::Test
8
8
  assert_equal 'hogehoge', 'hogehoge'.present(if: true)
9
9
  assert_equal 'hogehoge', 'hogehoge'.present(unless: false)
10
10
 
11
+ assert_equal '', 'hogehoge'.present(if: nil)
12
+
11
13
  assert_equal '', 'hogehoge'.present(if: false)
12
14
  assert_equal '', 'hogehoge'.present(unless: true)
13
15
  end
@@ -17,6 +19,8 @@ class TestString < Minitest::Test
17
19
  assert_equal '', 'hogehoge'.blank(if: true)
18
20
  assert_equal '', 'hogehoge'.blank(unless: false)
19
21
 
22
+ assert_equal 'hogehoge', 'hogehoge'.present(unless: nil)
23
+
20
24
  assert_equal 'hogehoge', 'hogehoge'.blank(if: false)
21
25
  assert_equal 'hogehoge', 'hogehoge'.blank(unless: true)
22
26
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: string-present-blank
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takashi Chiba
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-08 00:00:00.000000000 Z
11
+ date: 2014-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler