<commit_before># -*- coding: UTF-8 -*-

require "uri"
require "json"
require "open-uri"

require File.dirname(__FILE__) + "/ud/formatting"

# This module provide some methods to scrape definitions from the Urban
# Dictionary website.
module UD
  class << self
    # @return [String] the current gem's version
    def version
      "0.2.5"
    end

    # Get the search URL to query for a given term.
    # @param term [String] the term to search for. It must be a string, spaces
    #                      are allowed.
    # @param opts [Hash] options.
    # @return [String]
    def search_url(term, opts = {})
      param = URI.encode_www_form("term" => term)

      if opts[:api]
        "http://api.urbandictionary.com/v0/define?#{param}"
      else
        "http://www.urbandictionary.com/define.php?#{param}"
      end
    end

    # @param opts [Hash] options.
    def random_url(opts = {})
      if opts[:api]
        "http://api.urbandictionary.com/v0/random"
      else
        "http://www.urbandictionary.com/random.php"
      end
    end

    # Open the search URL in the user's browser
    # @param term [String] the term to search for. It must be a string, spaces
    #                      are allowed.
    # @return [Nil]
    def open_url(term = "")
      system open_cmd, search_url(term, false)
    end

    # Query the website and return a list of definitions for the provided term.
    # This list may be empty if there's no result.
    # @param term [String] the term to search for
    # @param opts [Hash] options. This is used by the command-line tool.
    #                    +:count+ is the maximum number of results to return
    # @return [Array<Hash>]<commit_msg>default :api to true in UD module<commit_after># -*- coding: UTF-8 -*-

require "uri"
require "json"
require "open-uri"

require File.dirname(__FILE__) + "/ud/formatting"

# This module provide some methods to scrape definitions from the Urban
# Dictionary website.
module UD
  class << self
    # @return [String] the current gem's version
    def version
      "0.2.5"
    end

    # Get the search URL to query for a given term.
    # @param term [String] the term to search for. It must be a string, spaces
    #                      are allowed.
    # @param opts [Hash] options.
    # @return [String]
    def search_url(term, opts = {})
      param = URI.encode_www_form("term" => term)

      if opts[:api] != false
        "http://api.urbandictionary.com/v0/define?#{param}"
      else
        "http://www.urbandictionary.com/define.php?#{param}"
      end
    end

    # @param opts [Hash] options.
    def random_url(opts = {})
      if opts[:api] != false
        "http://api.urbandictionary.com/v0/random"
      else
        "http://www.urbandictionary.com/random.php"
      end
    end

    # Open the search URL in the user's browser
    # @param term [String] the term to search for. It must be a string, spaces
    #                      are allowed.
    # @return [Nil]
    def open_url(term = "")
      system open_cmd, search_url(term, false)
    end

    # Query the website and return a list of definitions for the provided term.
    # This list may be empty if there's no result.
    # @param term [String] the term to search for
    # @param opts [Hash] options. This is used by the command-line tool.
    #                    +:count+ is the maximum number of results to return
    # @return [Array<Hash>]
{'fraction_non_alphanumeric': 0.10841613091759206, 'fraction_numerical': 0.0035067212156633548, 'mean_word_length': 2.2693409742120343, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, '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': '279246', 'n_tokens_mistral': 1032, 'n_tokens_neox': 1012, 'n_words': 371}