Class: TextTemplateMachine
- Inherits:
-
Object
- Object
- TextTemplateMachine
- Defined in:
- lib/scaffold/text_template_machine.rb
Instance Attribute Summary collapse
-
#placeholder_values ⇒ Object
Returns the value of attribute placeholder_values.
Instance Method Summary collapse
-
#initialize(shell) ⇒ TextTemplateMachine
constructor
A new instance of TextTemplateMachine.
- #render(text) ⇒ Object
- #replace_placeholder(text, placeholder, value) ⇒ Object
Constructor Details
#initialize(shell) ⇒ TextTemplateMachine
Returns a new instance of TextTemplateMachine.
5 6 7 8 |
# File 'lib/scaffold/text_template_machine.rb', line 5 def initialize shell @shell = shell @placeholder_values = [] end |
Instance Attribute Details
#placeholder_values ⇒ Object
Returns the value of attribute placeholder_values.
3 4 5 |
# File 'lib/scaffold/text_template_machine.rb', line 3 def placeholder_values @placeholder_values end |
Instance Method Details
#render(text) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/scaffold/text_template_machine.rb', line 10 def render text @placeholder_values.each do |placeholder_value| placeholder = placeholder_value.first value = placeholder_value.last text = replace_placeholder text, placeholder, value end text end |
#replace_placeholder(text, placeholder, value) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/scaffold/text_template_machine.rb', line 19 def replace_placeholder text, placeholder, value text = text.gsub "%#{placeholder}%", value placeholder_cap = placeholder.capitalize value_cap = value.capitalize text.gsub "%#{placeholder_cap}%", value_cap end |