string-present-blank 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/string_present_blank/string.rb +10 -4
- data/lib/string_present_blank/version.rb +1 -1
- data/test/test_string.rb +4 -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: 12a9f9884b8a55f32c2d73df048ac61af2f8690d
|
4
|
+
data.tar.gz: 7ea0bd9dcc876d361720591c3a43c720b741c609
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
5
|
-
|
4
|
+
if_condition = if conditions.has_key?(:if)
|
5
|
+
conditions.delete(:if)
|
6
|
+
else
|
7
|
+
true
|
8
|
+
end
|
6
9
|
|
7
|
-
unless_condition = conditions.
|
8
|
-
|
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
|
data/test/test_string.rb
CHANGED
@@ -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.
|
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-
|
11
|
+
date: 2014-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|