rego-ruby-ext 0.0.3 → 0.0.4

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.3
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 = {})
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rego-ruby-ext}
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Alex Tkachev"]
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: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Alex Tkachev