Class: Factbase::Env
- Inherits:
-
TermBase
- Object
- TermBase
- Factbase::Env
- 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
-
#evaluate(fact, maps, fb) ⇒ String
Evaluate term on a fact.
-
#initialize(operands) ⇒ Env
constructor
Constructor.
Constructor Details
#initialize(operands) ⇒ Env
Constructor.
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.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/factbase/terms/env.rb', line 23 def evaluate(fact, maps, fb) assert_args(2) n = _values(0, fact, maps, fb) return if n.nil? ENV.fetch(n[0].upcase) do d = _values(1, fact, maps, fb) return if d.nil? d[0] end end |