Class: ConvenientService::Utils::Bool::ToEnvBool

Inherits:
Support::Command show all
Defined in:
lib/convenient_service/utils/bool/to_env_bool.rb

Overview

Converts objects to boolean. Implementation is very basic just to serve the need of this library. More comprehensive solution can be found in Rails, wannabe_bool, etc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Support::Command

[], call

Constructor Details

#initialize(object) ⇒ void

Parameters:

  • object (Object)

    Can be any type.



29
30
31
# File 'lib/convenient_service/utils/bool/to_env_bool.rb', line 29

def initialize(object)
  @object = object
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



23
24
25
# File 'lib/convenient_service/utils/bool/to_env_bool.rb', line 23

def object
  @object
end

Instance Method Details

#callBoolean

Returns:

  • (Boolean)


36
37
38
39
40
41
# File 'lib/convenient_service/utils/bool/to_env_bool.rb', line 36

def call
  return true if object == "true"
  return true if object == "1"

  !!object
end