pebbles-php_cond 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +5 -0
- data/README.md +1 -0
- data/Rakefile +3 -0
- data/lib/pebbles-php_cond.rb +17 -14
- data/lib/pebbles-php_cond/version.rb +1 -1
- data/pebbles-php_cond.gemspec +3 -1
- data/spec/php_cond_spec.rb +3 -0
- metadata +19 -2
data/.travis.yml
ADDED
data/README.md
CHANGED
data/Rakefile
CHANGED
data/lib/pebbles-php_cond.rb
CHANGED
@@ -1,32 +1,35 @@
|
|
1
|
+
require 'pebbles-php_cond/version'
|
2
|
+
|
1
3
|
module Pebbles
|
2
4
|
module PhpCond
|
3
5
|
def self.bool(value)
|
4
|
-
return false if value.nil? || value
|
5
|
-
return value
|
6
|
-
return value.count
|
7
|
-
return value.to_s.size
|
6
|
+
return false if value.nil? || value.equal?(false) || value.eql?(0) || value.eql?(0.0)
|
7
|
+
return !(value.empty? || value === '0') if value.is_a?(String)
|
8
|
+
return !value.count.eql?(0) if value.respond_to?(:count)
|
9
|
+
return !value.to_s.size.eql?(0)
|
8
10
|
end
|
9
11
|
|
10
12
|
def self.equal?(rhs, lhs)
|
11
|
-
return true if rhs
|
13
|
+
return true if rhs.equal?(lhs)
|
12
14
|
|
13
|
-
return bool(lhs) if rhs
|
14
|
-
return bool(rhs) if lhs
|
15
|
+
return bool(lhs) if rhs.equal?(true)
|
16
|
+
return bool(rhs) if lhs.equal?(true)
|
15
17
|
|
16
|
-
return !bool(lhs) if rhs
|
17
|
-
return !bool(rhs) if lhs
|
18
|
+
return !bool(lhs) if rhs.equal?(false)
|
19
|
+
return !bool(rhs) if lhs.equal?(false)
|
18
20
|
|
19
21
|
return equal_as_numeric(rhs, lhs) if rhs.is_a?(Numeric)
|
20
22
|
return equal_as_numeric(lhs, rhs) if lhs.is_a?(Numeric)
|
21
23
|
|
22
|
-
return !(lhs
|
23
|
-
return !(rhs
|
24
|
+
return !(lhs === '0' || bool(lhs)) if rhs.nil?
|
25
|
+
return !(rhs === '0' || bool(rhs)) if lhs.nil?
|
24
26
|
|
27
|
+
return rhs.eql?(lhs) if rhs.class == lhs.class
|
25
28
|
return false if rhs.is_a?(String) || lhs.is_a?(String)
|
26
29
|
|
27
|
-
return true if rhs.is_a?(Enumerable) && lhs.is_a?(Enumerable) && rhs.count
|
30
|
+
return true if rhs.is_a?(Enumerable) && lhs.is_a?(Enumerable) && rhs.count.eql?(0) && lhs.count.eql?(0)
|
28
31
|
|
29
|
-
return false
|
32
|
+
return false
|
30
33
|
end
|
31
34
|
|
32
35
|
def self.identical?(rhs, lhs)
|
@@ -35,7 +38,7 @@ module Pebbles
|
|
35
38
|
|
36
39
|
private
|
37
40
|
def self.equal_as_numeric(own, other)
|
38
|
-
return other.respond_to?(:to_f) && other.to_f
|
41
|
+
return other.respond_to?(:to_f) && other.to_f.<=>(own).equal?(0) || other.respond_to?(:to_i) && other.to_i.equal?(own)
|
39
42
|
end
|
40
43
|
end
|
41
44
|
end
|
data/pebbles-php_cond.gemspec
CHANGED
@@ -17,5 +17,7 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
|
20
|
-
|
20
|
+
|
21
|
+
gem.add_development_dependency 'rspec'
|
22
|
+
gem.add_development_dependency 'rake'
|
21
23
|
end
|
data/spec/php_cond_spec.rb
CHANGED
@@ -17,6 +17,7 @@ describe Pebbles::PhpCond do
|
|
17
17
|
PhpCond::bool("abc").should be true
|
18
18
|
PhpCond::bool("0abc").should be true
|
19
19
|
PhpCond::bool("0.0").should be true
|
20
|
+
PhpCond::bool("0e0").should be true
|
20
21
|
PhpCond::bool("01").should be true
|
21
22
|
end
|
22
23
|
|
@@ -207,6 +208,8 @@ describe Pebbles::PhpCond do
|
|
207
208
|
PhpCond::equal?([1], [2]).should be false
|
208
209
|
PhpCond::equal?([3], [3]).should be true
|
209
210
|
|
211
|
+
PhpCond::equal?(0, '0e0').should be true
|
212
|
+
PhpCond::equal?(0, '0.0').should be true
|
210
213
|
end
|
211
214
|
|
212
215
|
it 'identical' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pebbles-php_cond
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-12-
|
12
|
+
date: 2012-12-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -27,6 +27,22 @@ dependencies:
|
|
27
27
|
- - ! '>='
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
30
46
|
description: emulate PHP condition
|
31
47
|
email:
|
32
48
|
- do.hiroaki@gmail.com
|
@@ -35,6 +51,7 @@ extensions: []
|
|
35
51
|
extra_rdoc_files: []
|
36
52
|
files:
|
37
53
|
- .gitignore
|
54
|
+
- .travis.yml
|
38
55
|
- Gemfile
|
39
56
|
- LICENSE.txt
|
40
57
|
- README.md
|