Class: TextTemplateMachine

Inherits:
Object
  • Object
show all
Defined in:
app/text_template_machine.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(shell) ⇒ TextTemplateMachine

Returns a new instance of TextTemplateMachine.



5
6
7
8
# File 'app/text_template_machine.rb', line 5

def initialize shell
  @shell =  shell
  @placeholder_values = []
end

Instance Attribute Details

#placeholder_valuesObject

Returns the value of attribute placeholder_values.



3
4
5
# File 'app/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 'app/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 'app/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