<commit_before>require 'sparkle_formation'
require 'multi_json'
require 'logger'

class SparkleFormation
  # Translator
  class Translation

    autoload :Heat, 'sparkle_formation/translation/heat'
    autoload :Rackspace, 'sparkle_formation/translation/rackspace'

    include SparkleFormation::Utils::AnimalStrings
    include SparkleFormation::SparkleAttribute

    # @return [Hash] original template
    attr_reader :original
    # @return [Hash] current translation
    attr_reader :translated
    # @return [Hash] duplicated template (full deep copy)
    attr_reader :template
    # @return [Logger] current logger
    attr_reader :logger
    # @return [Hash] parameters for template
    attr_reader :parameters
    # @return [Hash] extra options (generally used by translation implementations)
    attr_reader :options

    # Create new instance
    #
    # @param template_hash [Hash] stack template
    # @param args [Hash]
    # @option args [Logger] :logger custom logger
    # @option args [Hash] :parameters parameters for stack creation
    # @option args [Hash] :options options for translation
    def initialize(template_hash, args={})
      @original = template_hash.dup
      @template = MultiJson.load(MultiJson.dump(template_hash)) ## LOL: Lazy deep dup
      @translated = {}
      @logger = args.fetch(:logger, Logger.new($stdout))
      @parameters = args.fetch(:parameters, {})
      @options = args.fetch(:options, {})
    end

    # @return [Hash] resource mapping
    def map
      self.class.const_get(:MAP)
    end

    # Translate stack definition
    #
    # @return [TrueClass]
    def translate!
      template.each do |key, value|
        translate_method = "translate_#{snake(key.to_s)}".to_sym
        if(respond_to?(translate_method))
          send(translate_method, value)
        else
          translate_default(key, value)
        end<commit_msg>Provide composite parameter hash with defaults merged with user defined<commit_after>require 'sparkle_formation'
require 'multi_json'
require 'logger'

class SparkleFormation
  # Translator
  class Translation

    autoload :Heat, 'sparkle_formation/translation/heat'
    autoload :Rackspace, 'sparkle_formation/translation/rackspace'

    include SparkleFormation::Utils::AnimalStrings
    include SparkleFormation::SparkleAttribute

    # @return [Hash] original template
    attr_reader :original
    # @return [Hash] current translation
    attr_reader :translated
    # @return [Hash] duplicated template (full deep copy)
    attr_reader :template
    # @return [Logger] current logger
    attr_reader :logger
    # @return [Hash] extra options (generally used by translation implementations)
    attr_reader :options

    # Create new instance
    #
    # @param template_hash [Hash] stack template
    # @param args [Hash]
    # @option args [Logger] :logger custom logger
    # @option args [Hash] :parameters parameters for stack creation
    # @option args [Hash] :options options for translation
    def initialize(template_hash, args={})
      @original = template_hash.dup
      @template = MultiJson.load(MultiJson.dump(template_hash)) ## LOL: Lazy deep dup
      @translated = {}
      @logger = args.fetch(:logger, Logger.new($stdout))
      @parameters = args[:parameters] || {}
      @options = args[:options] || {}
    end

    # @return [Hash] parameters for template
    def parameters
      Hash[
        @original['Parameters'].map do |k,v|
          [k, v.fetch('Default', '')]
        end
      ].merge(@parameters)
    end

    # @return [Hash] resource mapping
    def map
      self.class.const_get(:MAP)
    end

    # Translate stack definition
    #
    # @return [TrueClass]
    def translate!
      template.each do |key, value|
        translate_method = "translate_#{snake(key.to_s)}".to_sym
        if(respond_to?(translate_method))
          send(translate_method, value)
        else
          translate_default(key, value)
        end
{'fraction_non_alphanumeric': 0.09767794043412419, 'fraction_numerical': 0.0, 'mean_word_length': 3.288961038961039, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5984226', 'n_tokens_mistral': 1133, 'n_tokens_neox': 1089, 'n_words': 309}