<commit_before>
require "pp" # pretty-print

module Cigale
  class Exts
    # Lets you do `dig(hash, "a.b.c")` instead of `hash["a"]["b"]["c"]`
    def dig(h, dotted_path)
      parts = dotted_path.split '.', 2
      match = h[parts[0]]
      if !parts[1] or match.nil?
        return match
      else
        return dig(match, parts[1])
      end
    end

    # Given {:a => b, :c => d, :e => f}, returns [:a, b]
    def first_pair(h)
      h.each_pair.next
    end

    # Given `{"a" => "b"}`, returns ["a", "b"].
    # Given `"a"`, returns ["a", {}]
    def asplode(node)
      type = nil
      spec = {}

      case node
      when Hash
        type, spec = first_pair(node)
      when String
        type = node
      else
        raise "Invalid markup: #{b.inspect}"
      end

      return type, spec
    end

    # Make sure something is an array
    def toa (input)
      case input
      when Array
        return input
      when nil
        return []
      else
        return [input]
      end
    end

    # Make sure something is a hash
    def toh (input)
      case input<commit_msg>fix error message on invalid markup<commit_after>
require "pp" # pretty-print

module Cigale
  class Exts
    # Lets you do `dig(hash, "a.b.c")` instead of `hash["a"]["b"]["c"]`
    def dig(h, dotted_path)
      parts = dotted_path.split '.', 2
      match = h[parts[0]]
      if !parts[1] or match.nil?
        return match
      else
        return dig(match, parts[1])
      end
    end

    # Given {:a => b, :c => d, :e => f}, returns [:a, b]
    def first_pair(h)
      h.each_pair.next
    end

    # Given `{"a" => "b"}`, returns ["a", "b"].
    # Given `"a"`, returns ["a", {}]
    def asplode(node)
      type = nil
      spec = {}

      case node
      when Hash
        type, spec = first_pair(node)
      when String
        type = node
      else
        raise "Invalid markup: #{node.inspect}"
      end

      return type, spec
    end

    # Make sure something is an array
    def toa (input)
      case input
      when Array
        return input
      when nil
        return []
      else
        return [input]
      end
    end

    # Make sure something is a hash
    def toh (input)
      case input
{'fraction_non_alphanumeric': 0.1258426966292135, 'fraction_numerical': 0.0035955056179775282, 'mean_word_length': 1.7413793103448276, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1156817', 'n_tokens_mistral': 751, 'n_tokens_neox': 735, 'n_words': 244}