Class: Nay::Template

Inherits:
Object
  • Object
show all
Defined in:
lib/nay/template.rb

Overview

Built on top of the string-based Lexer/Evaluator but instead of only working for a string, this will recursively evaluate all strings within an object. Heuristics:

- Hashes will have their keys and parameters traversed
- Arrays will have their entries traversed
- Strings evaluate using Lexer
- All other types will simply return themselves (not be traversed or use the Lexer)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ Template

Returns a new instance of Template.



16
17
18
19
20
# File 'lib/nay/template.rb', line 16

def initialize(object)
  @object = object

  freeze
end

Instance Attribute Details

#objectObject (readonly)

Returns the value of attribute object.



14
15
16
# File 'lib/nay/template.rb', line 14

def object
  @object
end

Instance Method Details

#evaluate(parameters = {}) ⇒ Object



22
23
24
# File 'lib/nay/template.rb', line 22

def evaluate(parameters = {})
  recursive_evaluate(object, parameters)
end