Class: Kramdown::PlantUml::BoolEnv

Inherits:
Object
  • Object
show all
Defined in:
lib/kramdown-plantuml/bool_env.rb

Overview

Converts envrionment variables to boolean values

Constant Summary collapse

TRUTHY_VALUES =
%w[t true yes y 1].freeze
FALSEY_VALUES =
%w[f false n no 0].freeze

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ BoolEnv

Returns a new instance of BoolEnv.



10
11
12
13
14
# File 'lib/kramdown-plantuml/bool_env.rb', line 10

def initialize(name)
  @name = name
  value = ENV.fetch(name, nil)
  @value = value.to_s.downcase unless value.nil?
end

Instance Method Details

#true?Boolean

Returns:

  • (Boolean)


16
17
18
19
20
21
# File 'lib/kramdown-plantuml/bool_env.rb', line 16

def true?
  return true if TRUTHY_VALUES.include?(@value)
  return false if FALSEY_VALUES.include?(@value) || @value.nil? || value.empty?

  raise "The value '#{@value}' of '#{@name}' can't be converted to a boolean"
end