module Poesie

Constants

VERSION

Public Class Methods

exit_with_error(message) click to toggle source
# File lib/poesie.rb, line 11
def self.exit_with_error(message)
  Log::error message
  exit 1
end
process(text, substitutions) click to toggle source

Apply the list of text substitutions to the given string

@param [String] text

The text to process

@param [Hash<String,String>] substitutions

The substitutions to apply
# File lib/poesie.rb, line 23
def self.process(text, substitutions)
  return text if substitutions.nil?
  replaced = text.dup
  list = substitutions
  list = [substitutions] if substitutions.is_a?(Hash)
  list.each do |hash|
    hash.each do |k,v|
      # If the key is surrounding by slashes, interpret as a RegExp
      k = Regexp.new($1) if k =~ %r(^/(.*)/$)
      replaced.gsub!(k, v)
    end
  end
  replaced
end