Class: Warg::Script::Interpolations
- Inherits:
-
Object
- Object
- Warg::Script::Interpolations
- Defined in:
- lib/warg.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.
2122 2123 2124 2125 |
# File 'lib/warg.rb', line 2122 def initialize(context) @context = context @values = {} end |
Instance Method Details
#[](key) ⇒ Object
2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 |
# File 'lib/warg.rb', line 2135 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
2146 2147 2148 |
# File 'lib/warg.rb', line 2146 def []=(key, value) @values[key] = value end |
#key?(key) ⇒ Boolean
2127 2128 2129 2130 2131 2132 2133 |
# File 'lib/warg.rb', line 2127 def key?(key) if key =~ CONTEXT_REGEXP @context.variables_set_defined?($1) else @values.key?(key) end end |