<commit_before>require 'timeout'

module Symbiont
  module Element
    def element(name, *identifier)
      build(name, *identifier) do
        define_method(name.to_s) do |*options|
          find_first(*identifier, *options)
        end
      end
    end

    def elements(name, *identifier)
      build(name, *identifier) do
        define_method(name.to_s) do |*options|
          find_all(*identifier, *options)
        end
      end
    end

    def region(name, *identifier, &block)
      region_class, region_args = extract_region_details(identifier, &block)

      build(name, *region_args) do
        define_method(name) do
          region_class.new(self, find_first(*region_args))
        end
      end
    end

    def regions(name, *identifier, &block)
      region_class, region_args = extract_region_details(identifier, &block)
      build(name, *region_args) do
        define_method(name) do
          puts "REGION ARGS: #{region_args}"
          find_all(*region_args).map do |element|
            puts "ELEMENT: #{element}"
            region_class.new(self, element)
          end
        end
      end
    end

    private

    def build(name, *identifier)
      add_to_mapped_elements(name)
      yield
      add_element_methods(name, *identifier)
    end

    def add_to_mapped_elements(name)
      @mapped_elements ||= []
      @mapped_elements << name.to_s
    end

    def add_element_methods(name, *identifier)
      create_existence_check(name, *identifier)
      create_nonexistence_check(name, *identifier)
      create_wait_check(name, *identifier)
      create_visible_check(name, *identifier)
      create_invisible_check(name, *identifier)
    end

    def create_element_method(_name, *_identifier)
      yield
    end<commit_msg>Add ability to support query options in regions.<commit_after>require 'timeout'

module Symbiont
  module Element
    def element(name, *identifier)
      build(name, *identifier) do
        define_method(name.to_s) do |*options|
          find_first(*identifier, *options)
        end
      end
    end

    def elements(name, *identifier)
      build(name, *identifier) do
        define_method(name.to_s) do |*options|
          find_all(*identifier, *options)
        end
      end
    end

    def region(name, *identifier, &block)
      region_class, region_args = extract_region_details(identifier, &block)

      build(name, *region_args) do
        define_method(name) do |*options|
          region_class.new(self, find_first(*region_args, *options))
        end
      end
    end

    def regions(name, *identifier, &block)
      region_class, region_args = extract_region_details(identifier, &block)

      build(name, *region_args) do
        define_method(name) do |*options|
          find_all(*region_args, *options).map do |element|
            region_class.new(self, element)
          end
        end
      end
    end

    private

    def build(name, *identifier)
      add_to_mapped_elements(name)
      yield
      add_element_methods(name, *identifier)
    end

    def add_to_mapped_elements(name)
      @mapped_elements ||= []
      @mapped_elements << name.to_s
    end

    def add_element_methods(name, *identifier)
      create_existence_check(name, *identifier)
      create_nonexistence_check(name, *identifier)
      create_wait_check(name, *identifier)
      create_visible_check(name, *identifier)
      create_invisible_check(name, *identifier)
    end

    def create_element_method(_name, *_identifier)
      yield
    end
{'fraction_non_alphanumeric': 0.08933635847986386, 'fraction_numerical': 0.0, 'mean_word_length': 2.740190880169671, 'pattern_counts': {'":': 0, '<': 7, '<?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': '7369246', 'n_tokens_mistral': 1074, 'n_tokens_neox': 1053, 'n_words': 233}