<commit_before>class Myhash

  def initialize(hash)
    @h = hash
  end

  def to_plain
    new_h = {}

    @h.each{|k, v|
      v2 =
        if v.is_a? Myhash
          v.to_plain
        else
          v
        end
      new_h[k] = v2
    }

    new_h
  end

  def to_sym_key()
    new_h = {}

    @h.each do |k, v|
      _v =
        if v.is_a? Hash
          to_sym_key(v)
        else
          v
        end

      _k =
        if k.is_a? String
          k.to_sym
        else
          k
        end

      new_h[_k] = _v
    end

    Myhash.new(new_h)
  end

  def self.to_sym_key(hash)
    Myhash.new(hash)
      .to_sym_key
      .to_plain
  end

  # to snake case
  def self._to_snake(arg)
    is_sym = arg.is_a?(Symbol)

    s = is_sym ? arg.to_s : arg

    new_s = s.chars
      .map do |c|
        if /^[A-Z]$/ =~ c
          "_" + c.downcase
        else
          c
        end
      end
      .join("")

    is_sym ? new_s.to_sym : new_s
  end

  def to_snake
    new_h = {}
    @h.each{|k, v|
      new_k = Myhash._to_snake(k.to_s)

      new_v =
        if v.is_a? Hash
          Myhash.new(v).to_snake
        else
          v
        end

      new_h[new_k] = new_v
    }

    Myhash.new(new_h)
  end

  # to lower camel case
  def self._to_lcc(arg)
    is_sym = arg.is_a?(Symbol)

    s = is_sym ? arg.to_s : arg

    words = s.split("_")

    new_s =
      words[0] +
      words[1..-1]
        .map{|word| word.capitalize }
        .join("")

    is_sym ? new_s.to_sym : new_s
  end

  def to_lcc
    new_h = {}
    @h.each{|k, v|
      new_k = Myhash._to_lcc(k.to_s)

      new_v =
        if v.is_a? Hash
          Myhash.new(v).to_lcc
        else
          v
        end

      new_h[new_k] = new_v
    }

    Myhash.new(new_h)
  end

  def method_missing(name)
    unless @h.key? name.to_sym
      raise "key not found (#{name}) (#{ @h.inspect })"
    end
    val = @h[name.to_sym]

    if val.is_a? Hash
      Myhash.new(val)
    else
      val
    end
  end

end
<commit_msg>refactor: rename: => new_k, new_v (myhash)<commit_after>class Myhash

  def initialize(hash)
    @h = hash
  end

  def to_plain
    new_h = {}

    @h.each{|k, v|
      new_v =
        if v.is_a? Myhash
          v.to_plain
        else
          v
        end
      new_h[k] = new_v
    }

    new_h
  end

  def to_sym_key()
    new_h = {}

    @h.each do |k, v|
      new_v =
        if v.is_a? Hash
          to_sym_key(v)
        else
          v
        end

      new_k =
        if k.is_a? String
          k.to_sym
        else
          k
        end

      new_h[new_k] = new_v
    end

    Myhash.new(new_h)
  end

  def self.to_sym_key(hash)
    Myhash.new(hash)
      .to_sym_key
      .to_plain
  end

  # to snake case
  def self._to_snake(arg)
    is_sym = arg.is_a?(Symbol)

    s = is_sym ? arg.to_s : arg

    new_s = s.chars
      .map do |c|
        if /^[A-Z]$/ =~ c
          "_" + c.downcase
        else
          c
        end
      end
      .join("")

    is_sym ? new_s.to_sym : new_s
  end

  def to_snake
    new_h = {}
    @h.each{|k, v|
      new_k = Myhash._to_snake(k.to_s)

      new_v =
        if v.is_a? Hash
          Myhash.new(v).to_snake
        else
          v
        end

      new_h[new_k] = new_v
    }

    Myhash.new(new_h)
  end

  # to lower camel case
  def self._to_lcc(arg)
    is_sym = arg.is_a?(Symbol)

    s = is_sym ? arg.to_s : arg

    words = s.split("_")

    new_s =
      words[0] +
      words[1..-1]
        .map{|word| word.capitalize }
        .join("")

    is_sym ? new_s.to_sym : new_s
  end

  def to_lcc
    new_h = {}
    @h.each{|k, v|
      new_k = Myhash._to_lcc(k.to_s)

      new_v =
        if v.is_a? Hash
          Myhash.new(v).to_lcc
        else
          v
        end

      new_h[new_k] = new_v
    }

    Myhash.new(new_h)
  end

  def method_missing(name)
    unless @h.key? name.to_sym
      raise "key not found (#{name}) (#{ @h.inspect })"
    end
    val = @h[name.to_sym]

    if val.is_a? Hash
      Myhash.new(val)
    else
      val
    end
  end

end

{'fraction_non_alphanumeric': 0.11198621708097464, 'fraction_numerical': 0.0019689884321929607, 'mean_word_length': 1.296045197740113, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '3694423', 'n_tokens_mistral': 1753, 'n_tokens_neox': 1682, 'n_words': 348}