rego-ruby-ext 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/string.rb +11 -0
- data/rego-ruby-ext.gemspec +1 -1
- data/spec/string_spec.rb +18 -0
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/lib/string.rb
CHANGED
@@ -17,6 +17,17 @@ class String
|
|
17
17
|
hash
|
18
18
|
end
|
19
19
|
|
20
|
+
# converts string to either TrueClass or FalseClass. If converion can't be made, returns nil
|
21
|
+
def to_boolean
|
22
|
+
s = self.downcase.strip
|
23
|
+
if s == 'true'
|
24
|
+
TrueClass
|
25
|
+
elsif s == 'false'
|
26
|
+
FalseClass
|
27
|
+
else
|
28
|
+
nil
|
29
|
+
end
|
30
|
+
end
|
20
31
|
|
21
32
|
# matches and replaces placeholders in form of %{foo} or %<foo>
|
22
33
|
def interpolate(values_hash = {}, options = {})
|
data/rego-ruby-ext.gemspec
CHANGED
data/spec/string_spec.rb
CHANGED
@@ -18,4 +18,22 @@ describe String do
|
|
18
18
|
"var is %{var1}!".interpolate(:var1 => 10).should == "var is 10!"
|
19
19
|
end
|
20
20
|
|
21
|
+
describe '#to_boolean' do
|
22
|
+
it 'should return nil for non boolean strings' do
|
23
|
+
"asdf".to_boolean.should be_nil
|
24
|
+
"0".to_boolean.should be_nil
|
25
|
+
end
|
26
|
+
it 'should return TrueClass for true strings' do
|
27
|
+
"true".to_boolean.should be_true
|
28
|
+
" true ".to_boolean.should be_true
|
29
|
+
" TRuE".to_boolean.should be_true
|
30
|
+
end
|
31
|
+
it 'should return FalseClass for true strings' do
|
32
|
+
"false".to_boolean.should be_true
|
33
|
+
" false ".to_boolean.should be_true
|
34
|
+
" FALse".to_boolean.should be_true
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
21
39
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rego-ruby-ext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Alex Tkachev
|