<commit_before># encoding: utf-8

module SetupConfiguration

  # The <code>BinaryCodedValues</code> mixin provides common methods for transforming meaningful values
  # in binary coded values - and vice versa.
  # The class must provide a method <code>values</code>, which
  # delivers a hash with the values and its numbers.
  module BinaryCodedValues

    # Gets the number (or: numerical value) of the given value.
    def number(value)
      if values.has_key?(value)
        values[value]
      else
        raise ArgumentError.new("'#{value}' is not a valid option. Valid values: #{self.pretty}")
      end
    end

    # Gets the value to the given number.
    def value(number)
      # 60.to_s(2).chars.to_a.reverse.each_with_index { |s,i| puts s; puts i}
      result=[]
      unless number.eql?(0) then
        number.to_s(2).chars.to_a.reverse.each_with_index do |value, index|
          if value.eql?("1")
            # invert hash with values to get meaningful value (key) for given binary coded value
            role = values.invert[2**index]
            result << role if role
          end
        end
      end
      result
    end

    def pretty
      s = ""
      PP.pp(values.keys, s)
      s
    end<commit_msg>rename variable (remainder from refactoring)<commit_after># encoding: utf-8

module SetupConfiguration

  # The <code>BinaryCodedValues</code> mixin provides common methods for transforming meaningful values
  # in binary coded values - and vice versa.
  # The class must provide a method <code>values</code>, which
  # delivers a hash with the values and its numbers.
  module BinaryCodedValues

    # Gets the number (or: numerical value) of the given value.
    def number(value)
      if values.has_key?(value)
        values[value]
      else
        raise ArgumentError.new("'#{value}' is not a valid option. Valid values: #{self.pretty}")
      end
    end

    # Gets the value to the given number.
    def value(number)
      # 60.to_s(2).chars.to_a.reverse.each_with_index { |s,i| puts s; puts i}
      result=[]
      unless number.eql?(0) then
        number.to_s(2).chars.to_a.reverse.each_with_index do |value, index|
          if value.eql?("1")
            # invert hash with values to get meaningful value (key) for given binary coded value
            r = values.invert[2**index]
            result << r if r
          end
        end
      end
      result
    end

    def pretty
      s = ""
      PP.pp(values.keys, s)
      s
    end
{'fraction_non_alphanumeric': 0.09156626506024096, 'fraction_numerical': 0.00642570281124498, 'mean_word_length': 2.3707713125845737, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 11, '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': '6978484', 'n_tokens_mistral': 755, 'n_tokens_neox': 734, 'n_words': 255}