Class: EnvHelpers::Utils

Inherits:
Object
  • Object
show all
Defined in:
lib/env_helpers/utils.rb

Overview

Utility methods

Class Method Summary collapse

Class Method Details

.boolean_value?(val) ⇒ Boolean Also known as: bool_value?

Check if a value represents a boolean

Parameters:

  • val (Object)

    object to check if a boolean value

Returns:

  • (Boolean)


10
11
12
# File 'lib/env_helpers/utils.rb', line 10

def boolean_value?(val)
  true_value?(val) || false_value?(val)
end

.false_value?(val) ⇒ Boolean

Check if value represents ‘false`. (’false’, ‘f’, or ‘0’)

Parameters:

  • val (Object)

    object to check if a false value

Returns:

  • (Boolean)


32
33
34
35
36
37
38
39
40
# File 'lib/env_helpers/utils.rb', line 32

def false_value?(val)
  val = val.to_s.downcase

  return true if val == 'false'
  return true if val == 'f'
  return true if val == '0'

  false
end

.true_value?(val) ⇒ Boolean

Check if value represents ‘true`. (’true’, ‘t’, or ‘1’)

Parameters:

  • val (Object)

    object to check if a true value

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
27
# File 'lib/env_helpers/utils.rb', line 19

def true_value?(val)
  val = val.to_s.downcase

  return true if val == 'true'
  return true if val == 't'
  return true if val == '1'

  false
end