Class: EacTemplates::File

Inherits:
Object show all
Defined in:
lib/eac_templates/file.rb

Constant Summary collapse

VARIABLE_DELIMITER =
::Regexp.quote('%%')
VARIABLE_PATTERN =
/#{VARIABLE_DELIMITER}([a-z0-9\._]*)#{VARIABLE_DELIMITER}/i.freeze

Instance Method Summary collapse

Instance Method Details

#apply(variables_source) ⇒ Object

variables_provider A [Hash] or object which responds to read_entry(entry_name).



17
18
19
20
21
22
# File 'lib/eac_templates/file.rb', line 17

def apply(variables_source)
  variables_provider = ::EacTemplates::VariableProviders.build(variables_source)
  variables.inject(content) do |a, e|
    a.gsub(variable_pattern(e), variables_provider.variable_value(e).to_s)
  end
end

#apply_to_file(variables_source, output_file_path) ⇒ Object



24
25
26
# File 'lib/eac_templates/file.rb', line 24

def apply_to_file(variables_source, output_file_path)
  output_file_path.to_pathname.write(apply(variables_source))
end