<commit_before>require 'nugrant/bag'
require 'nugrant/helper/bag'

module Nugrant
  class Parameters
    attr_reader :__current, :__user, :__system, :__defaults, :__all

    ##
    # Create a new parameters object which holds completed
    # merged values. The following precedence is used to decide
    # which location has precedence over which location:
    #
    #    (Highest)  ------------------ (Lowest)
    #      current < user < system < defaults
    #
    # =| Options
    #  * +:config+   - A hash that will be passed to Nugrant::Config.new().
    #                  See Nugrant::Config constructor for options that you can use.
    #  * +:defaults+ - The default values for the various parameters that will be read. This
    #                  must be a Hash object.
    #
    def initialize(options = {})
      @__config = Config.new(options[:config])

      @__current = Helper::Bag.read(@__config.current_path, @__config.params_format)
      @__user = Helper::Bag.read(@__config.user_path, @__config.params_format)
      @__system = Helper::Bag.read(@__config.system_path, @__config.params_format)
      @__defaults = Bag.new(options[:defaults] || {})

      __compute_all()
    end

    def [](key)
      return @__all[key]
    end

    def method_missing(method, *args, &block)
      return  @__all[method.to_s]
    end

    def empty?()
      @__all.empty?()
    end

    def has?(key)
      return @__all.has?(key)
    end

    def each(&block)
      @__all.each(&block)
    end

    ##
    # Set the new default values for the
    # various parameters contain by this instance.
    # This will call __compute_all() to recompute
    # correct precedences.
    #
    # =| Attributes
    #  * +elements+ - The new default elements
    #
    def defaults=(elements)
      @__defaults = Bag.new(elements)

      # When defaults change, we need to recompute parameters hierarchy
      __compute_all()
    end

    ##
    # Recompute the correct precedences by merging the various
    # bag in the right order and return the result as a Nugrant::Bag
    # object.
    #
    def __compute_all()
      @__all = Bag.new()
      @__all.__merge!(@__defaults)
      @__all.__merge!(@__system)
      @__all.__merge!(@__user)
      @__all.__merge!(@__current)
    end
  end
end<commit_msg>Added a __to_hash() method to Parameters<commit_after>require 'nugrant/bag'
require 'nugrant/helper/bag'

module Nugrant
  class Parameters
    attr_reader :__current, :__user, :__system, :__defaults, :__all

    ##
    # Create a new parameters object which holds completed
    # merged values. The following precedence is used to decide
    # which location has precedence over which location:
    #
    #    (Highest)  ------------------ (Lowest)
    #      current < user < system < defaults
    #
    # =| Options
    #  * +:config+   - A hash that will be passed to Nugrant::Config.new().
    #                  See Nugrant::Config constructor for options that you can use.
    #  * +:defaults+ - The default values for the various parameters that will be read. This
    #                  must be a Hash object.
    #
    def initialize(options = {})
      @__config = Config.new(options[:config])

      @__current = Helper::Bag.read(@__config.current_path, @__config.params_format)
      @__user = Helper::Bag.read(@__config.user_path, @__config.params_format)
      @__system = Helper::Bag.read(@__config.system_path, @__config.params_format)
      @__defaults = Bag.new(options[:defaults] || {})

      __compute_all()
    end

    def [](key)
      return @__all[key]
    end

    def method_missing(method, *args, &block)
      return  @__all[method.to_s]
    end

    def empty?()
      @__all.empty?()
    end

    def has?(key)
      return @__all.has?(key)
    end

    def each(&block)
      @__all.each(&block)
    end

    ##
    # Set the new default values for the
    # various parameters contain by this instance.
    # This will call __compute_all() to recompute
    # correct precedences.
    #
    # =| Attributes
    #  * +elements+ - The new default elements
    #
    def defaults=(elements)
      @__defaults = Bag.new(elements)

      # When defaults change, we need to recompute parameters hierarchy
      __compute_all()
    end

    ##
    # Recompute the correct precedences by merging the various
    # bag in the right order and return the result as a Nugrant::Bag
    # object.
    #
    def __compute_all()
      @__all = Bag.new()
      @__all.__merge!(@__defaults)
      @__all.__merge!(@__system)
      @__all.__merge!(@__user)
      @__all.__merge!(@__current)
    end

    def __to_hash()
      @__all.__to_hash()
    end
  end
end
{'fraction_non_alphanumeric': 0.11303789338471419, 'fraction_numerical': 0.0, 'mean_word_length': 2.4658753709198815, 'pattern_counts': {'":': 0, '<': 9, '<?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': '3796270', 'n_tokens_mistral': 1442, 'n_tokens_neox': 1402, 'n_words': 402}