<commit_before>module Browser; module DOM

class NodeSet
  attr_reader :document

  def initialize(document, list = [])
    @document = document
    @literal  = []

    list.each {|el|
      if NodeSet === el
        @literal.concat(el.to_a)
      else
        @literal.push DOM(Native.try_convert(el))
      end
    }
  end

  def method_missing(name, *args, &block)
    unless @literal.respond_to? name
      each {|el|
        el.__send__(name, *args, &block)
      }

      return self
    end

    result = @literal.__send__ name, *args, &block

    if `result === #@literal`
      self
    elsif Array === result
      NodeSet.new(@document, result)
    else
      result
    end
  end

  def dup
    NodeSet.new(document, to_ary.dup)
  end

  def filter(expression)
    NodeSet.new(document, @internal.select { |node| node.matches?(expression) })
  end<commit_msg>dom/node_set: use Native.convert instead of Native.try_convert<commit_after>module Browser; module DOM

class NodeSet
  attr_reader :document

  def initialize(document, list = [])
    @document = document
    @literal  = []

    list.each {|el|
      if NodeSet === el
        @literal.concat(el.to_a)
      else
        @literal.push DOM(Native.convert(el))
      end
    }
  end

  def method_missing(name, *args, &block)
    unless @literal.respond_to? name
      each {|el|
        el.__send__(name, *args, &block)
      }

      return self
    end

    result = @literal.__send__ name, *args, &block

    if `result === #@literal`
      self
    elsif Array === result
      NodeSet.new(@document, result)
    else
      result
    end
  end

  def dup
    NodeSet.new(document, to_ary.dup)
  end

  def filter(expression)
    NodeSet.new(document, @internal.select { |node| node.matches?(expression) })
  end
{'fraction_non_alphanumeric': 0.11415780637940683, 'fraction_numerical': 0.0, 'mean_word_length': 2.458413926499033, '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': '2334182', 'n_tokens_mistral': 589, 'n_tokens_neox': 572, 'n_words': 144}