Module: Pebbles::PhpCond

Defined in:
lib/pebbles/php_cond.rb,
lib/pebbles/php_cond/version.rb

Constant Summary collapse

VERSION =
'0.0.3'

Class Method Summary collapse

Class Method Details

.bool(value) ⇒ Object



5
6
7
8
9
10
# File 'lib/pebbles/php_cond.rb', line 5

def self.bool(value)
  return false if value.nil? || value.equal?(false) || value.eql?(0) || value.eql?(0.0)
  return !(value.empty? || value === '0') if value.is_a?(String)
  return !value.count.eql?(0) if value.respond_to?(:count)
  return !value.to_s.size.eql?(0)
end

.equal?(rhs, lhs) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/pebbles/php_cond.rb', line 12

def self.equal?(rhs, lhs)
  return true if rhs.equal?(lhs)

  return bool(lhs) if rhs.equal?(true)
  return bool(rhs) if lhs.equal?(true)

  return !bool(lhs) if rhs.equal?(false)
  return !bool(rhs) if lhs.equal?(false)

  return equal_as_numeric(rhs, lhs) if rhs.is_a?(Numeric)
  return equal_as_numeric(lhs, rhs) if lhs.is_a?(Numeric)

  return !(lhs === '0' || bool(lhs)) if rhs.nil?
  return !(rhs === '0' || bool(rhs)) if lhs.nil?

  return rhs.eql?(lhs) if rhs.class == lhs.class
  return false if rhs.is_a?(String) || lhs.is_a?(String)

  return true if rhs.is_a?(Enumerable) && lhs.is_a?(Enumerable) && rhs.count.eql?(0) && lhs.count.eql?(0)

  return false
end

.identical?(rhs, lhs) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/pebbles/php_cond.rb', line 35

def self.identical?(rhs, lhs)
  return rhs == lhs
end