<commit_before># coding: utf-8
require 'mastar/version'
require 'mastar/configuration'
require 'mastar/name_value_pair'

module Mastar
  def self.included(base)
    base.extend(ClassMethods)
  end

  module ClassMethods
    # get NameValuePair array
    # options accepts name and value keys
    # options are first preference
    def pairs(options = {})
      opts = safe_options(options)
      name = extract_option_value(opts, :name, @mastar_config.name)
      value = extract_option_value(opts, :value, @mastar_config.value)
      self.select([name, value]).map { |r| NameValuePair.new(r.__send__(name), r.__send__(value)) }
    end

    # set configuration name, value, key at a time
    # and return config instance.
    def mastar(options = {})
      opts = safe_options(options)
      @mastar_config ||= Mastar::Configuration.new
      unless opts.empty?
        @mastar_config.name(extract_option_value(opts, :name))
        @mastar_config.value(extract_option_value(opts, :value))
        @mastar_config.key(extract_option_value(opts, :key))
      end
      @mastar_config
    end

    # if key configuration exists, define method of name and call
    def method_missing(name, *args)
      if @mastar_config.key
        define_direct_method(name)
        __send__(name, *args)
      else
        super
      end
    end

    private
    # if options is Hash, return options
    # else return initialized Hash
    def safe_options(options)
      options.is_a?(Hash) ? options : {}<commit_msg>add mastar_config method.always get config instance by way of this method refs #47<commit_after># coding: utf-8
require 'mastar/version'
require 'mastar/configuration'
require 'mastar/name_value_pair'

module Mastar
  def self.included(base)
    base.extend(ClassMethods)
  end

  module ClassMethods
    # get NameValuePair array
    # options accepts name and value keys
    # options are first preference
    def pairs(options = {})
      opts = safe_options(options)
      name = extract_option_value(opts, :name, mastar_config.name)
      value = extract_option_value(opts, :value, mastar_config.value)
      self.select([name, value]).map { |r| NameValuePair.new(r.__send__(name), r.__send__(value)) }
    end

    # set configuration name, value, key at a time
    # and return config instance.
    def mastar(options = {})
      opts = safe_options(options)
      unless opts.empty?
        mastar_config.name(extract_option_value(opts, :name))
        mastar_config.value(extract_option_value(opts, :value))
        mastar_config.key(extract_option_value(opts, :key))
      end
      mastar_config
    end

    # if key configuration exists, define method of name and call
    def method_missing(name, *args)
      if mastar_config.key
        define_direct_method(name)
        __send__(name, *args)
      else
        super
      end
    end

    private
    # get Mastar::Configuration instance
    def mastar_config
      @mastar_config ||= Mastar::Configuration.new
    end

    # if options is Hash, return options
    # else return initialized Hash
    def safe_options(options)
      options.is_a?(Hash) ? options : {}
{'fraction_non_alphanumeric': 0.09056122448979592, 'fraction_numerical': 0.0012755102040816326, 'mean_word_length': 3.1494708994708995, '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': '2793258', 'n_tokens_mistral': 958, 'n_tokens_neox': 955, 'n_words': 246}