Class: Factbase::Env

Inherits:
TermBase show all
Defined in:
lib/factbase/terms/env.rb

Overview

The ‘Factbase::Env` class is used to evaluate terms based on environment variables. It retrieves the value of an environment variable or returns a default value if the variable is not set.

Instance Method Summary collapse

Methods included from TermShared

#to_s

Constructor Details

#initialize(operands) ⇒ Env

Constructor.

Parameters:

  • operands (Array)

    Operands



13
14
15
16
# File 'lib/factbase/terms/env.rb', line 13

def initialize(operands)
  super()
  @operands = operands
end

Instance Method Details

#evaluate(fact, maps, fb) ⇒ String

Evaluate term on a fact.

Parameters:

Returns:

  • (String)

    The value of the environment variable or the default



23
24
25
26
27
# File 'lib/factbase/terms/env.rb', line 23

def evaluate(fact, maps, fb)
  assert_args(2)
  n = _values(0, fact, maps, fb)[0]
  ENV.fetch(n.upcase) { _values(1, fact, maps, fb)[0] }
end