Class: PageEz::SelectorEvaluator

Inherits:
Object
  • Object
show all
Defined in:
lib/page_ez/selector_evaluator.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, args, dynamic_options:, options:, selector:, target:) ⇒ SelectorEvaluator

Returns a new instance of SelectorEvaluator.



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/page_ez/selector_evaluator.rb', line 16

def initialize(name, args, dynamic_options:, options:, selector:, target:)
  @name = name
  @args = args
  @dynamic_options = dynamic_options
  @options = options
  @selector = if selector.respond_to?(:bind)
    selector.bind(target)
  else
    selector
  end
end

Class Method Details

.build(name, dynamic_options:, options:, selector:) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/page_ez/selector_evaluator.rb', line 3

def self.build(name, dynamic_options:, options:, selector:)
  run_def = ->(args, target:) do
    PageEz::SelectorEvaluator.new(name, args, dynamic_options: dynamic_options, options: options, selector: selector, target: target)
  end

  name_def = -> { name }

  Class.new.tap do |klass|
    klass.define_singleton_method(:run, &run_def)
    klass.define_singleton_method(:name, &name_def)
  end
end

Instance Method Details

#optionsObject



40
41
42
# File 'lib/page_ez/selector_evaluator.rb', line 40

def options
  Options.merge(@options, @dynamic_options, *args[selector_args.length..])
end

#selectorObject



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/page_ez/selector_evaluator.rb', line 28

def selector
  if dynamic_selector?
    if selector_args.none?
      @selector.call(**kwargs.slice(*selector_kwargs))
    else
      @selector.call(*args[0..selector_args.length - 1], **kwargs.slice(*selector_kwargs))
    end
  else
    @selector
  end
end