Module: OrangeLib::Variables
- Included in:
- Rest
- Defined in:
- lib/orange_lib/vars.rb
Instance Method Summary collapse
-
#clear_variables ⇒ Object
Remove all of stored variables.
-
#interpret_string(input, params = {}) ⇒ Object
Interpret an input string or hash by using the variable that set before that or the params argument.
-
#variable(name, value = nil) ⇒ Object
Create variable with input name and value.
Instance Method Details
#clear_variables ⇒ Object
Remove all of stored variables.
23 24 25 |
# File 'lib/orange_lib/vars.rb', line 23 def clear_variables variables.clear end |
#interpret_string(input, params = {}) ⇒ Object
Interpret an input string or hash by using the variable that set before that or the params argument
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/orange_lib/vars.rb', line 36 def interpret_string(input, params = {}) # Merge optional parameters with global variables params = variables.merge(params) params = flatten_hash(params) if input.class == Hash input.each { |k, v| input[k] = interpret_string(v) } elsif input.class == String && input =~ /(\%\{.+\})+/ input % params else input end end |
#variable(name, value = nil) ⇒ Object
Create variable with input name and value. If input value is not passed, method will return value of variable (This function is used if we would like to store a value to a variable in cucumber)
12 13 14 15 16 17 |
# File 'lib/orange_lib/vars.rb', line 12 def variable(name, value = nil) name = name.to_sym return variables[name] if value.nil? variables[name] = value end |