<commit_before>require "json"
require "jquery/version"

module Kernel
  def jQuery(*args)
    JQuery::Object.new(:jQuery, *args)
  end
end

module JQuery
  class Object
    attr_accessor :label, :args, :prev, :next

    def initialize(label, *args)
      @label = label.to_s
      @args  = args.map do |arg|
        case arg
        when String
          JSString.new(arg)
        when Numeric
          JSNumeric.new(arg)
        when Symbol
          JSVar.new(arg)
        when Array, Hash
          JSStruct.new(arg)
        when Proc
          JSFunction.new(arg)
        else
          raise ArgumentError.new("#{arg.class} is not supported")
        end
      end
    end

    def to_s
      current = self
      chain   = [current]

      while current.prev
        current = current.prev
        chain.unshift(current)
      end

      result = []
      chain.map do |obj|
        expr = ''
        expr << "#{obj.label}("
        expr << obj.args.map { |arg| arg.to_s }.join(',')
        expr << ')'
        result << expr
      end

      result.join('.')
    end

    def method_missing(method, *args)
      next_obj    = self.class.new(method, *args)
      self.next   = next_obj<commit_msg>Added `to_str` to convert object to string implicitely.<commit_after>require "json"
require "jquery/version"

module Kernel
  def jQuery(*args)
    JQuery::Object.new(:jQuery, *args)
  end
end

module JQuery
  class Object
    attr_accessor :label, :args, :prev, :next

    def initialize(label, *args)
      @label = label.to_s
      @args  = args.map do |arg|
        case arg
        when String
          JSString.new(arg)
        when Numeric
          JSNumeric.new(arg)
        when Symbol
          JSVar.new(arg)
        when Array, Hash
          JSStruct.new(arg)
        when Proc
          JSFunction.new(arg)
        else
          raise ArgumentError.new("#{arg.class} is not supported")
        end
      end
    end

    def to_s
      current = self
      chain   = [current]

      while current.prev
        current = current.prev
        chain.unshift(current)
      end

      result = []
      chain.map do |obj|
        expr = ''
        expr << "#{obj.label}("
        expr << obj.args.map { |arg| arg.to_s }.join(',')
        expr << ')'
        result << expr
      end

      result.join('.')
    end

    alias_method :to_str, :to_s

    def method_missing(method, *args)
      next_obj    = self.class.new(method, *args)
      self.next   = next_obj
{'fraction_non_alphanumeric': 0.10873942811115586, 'fraction_numerical': 0.0, 'mean_word_length': 1.7447513812154696, 'pattern_counts': {'":': 0, '<': 19, '<?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': '4252342', 'n_tokens_mistral': 792, 'n_tokens_neox': 776, 'n_words': 199}