Class: BoPeep::Script::Interpolations
- Inherits:
-
Object
- Object
- BoPeep::Script::Interpolations
- Defined in:
- lib/bopeep.rb
Constant Summary collapse
- CONTEXT_REGEXP =
/variables:(\w+)/
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
-
#initialize(context) ⇒ Interpolations
constructor
A new instance of Interpolations.
- #key?(key) ⇒ Boolean
Constructor Details
#initialize(context) ⇒ Interpolations
Returns a new instance of Interpolations.
2278 2279 2280 2281 |
# File 'lib/bopeep.rb', line 2278 def initialize(context) @context = context @values = {} end |
Instance Method Details
#[](key) ⇒ Object
2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 |
# File 'lib/bopeep.rb', line 2291 def [](key) if @values.key?(key) @values[key] elsif key =~ CONTEXT_REGEXP && @context.variables_set_defined?($1) variables = @context[$1] content = variables.to_h.sort.map { |key, value| %{#{key}="#{value}"} }.join("\n") @values[key] = content end end |
#[]=(key, value) ⇒ Object
2302 2303 2304 |
# File 'lib/bopeep.rb', line 2302 def []=(key, value) @values[key] = value end |
#key?(key) ⇒ Boolean
2283 2284 2285 2286 2287 2288 2289 |
# File 'lib/bopeep.rb', line 2283 def key?(key) if key =~ CONTEXT_REGEXP @context.variables_set_defined?($1) else @values.key?(key) end end |