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 ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ script: "bundle exec rake spec"
3
+ rvm:
4
+ - 1.9.3
5
+ - 1.9.2
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # Pebbles::PhpCond
2
+ [![Build Status](https://secure.travis-ci.org/do-aki/pebbles-php_cond.png?branch=master)](https://travis-ci.org/do-aki/pebbles-php_cond)
2
3
 
3
4
  PhpCond is emulate PHP condition in ruby
4
5
 
data/Rakefile CHANGED
@@ -1 +1,4 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
@@ -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 == false || value == 0 || value == 0.0
5
- return value != '' && value != '0' if value.is_a?(String)
6
- return value.count != 0 if value.respond_to?(:count)
7
- return value.to_s.size != 0
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 == lhs
13
+ return true if rhs.equal?(lhs)
12
14
 
13
- return bool(lhs) if rhs == true
14
- return bool(rhs) if lhs == true
15
+ return bool(lhs) if rhs.equal?(true)
16
+ return bool(rhs) if lhs.equal?(true)
15
17
 
16
- return !bool(lhs) if rhs == false
17
- return !bool(rhs) if lhs == false
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 == '0' || bool(lhs)) if (rhs.nil?)
23
- return !(rhs == '0' || bool(rhs)) if (lhs.nil?)
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 == 0 && lhs.count == 0
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 == own || other.respond_to?(:to_i) && other.to_i == own
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
@@ -1,5 +1,5 @@
1
1
  module Pebbles
2
2
  module PhpCond
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.2'
4
4
  end
5
5
  end
@@ -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
- gem.add_development_dependency "rspec"
20
+
21
+ gem.add_development_dependency 'rspec'
22
+ gem.add_development_dependency 'rake'
21
23
  end
@@ -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.1
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-01 00:00:00.000000000 Z
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