Class: Puppeteer::QueryHandlerManager

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/puppeteer/query_handler_manager.rb

Defined Under Namespace

Classes: Result

Instance Method Summary collapse

Instance Method Details

#detect_query_handler(selector) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/puppeteer/query_handler_manager.rb', line 42

def detect_query_handler(selector)
  unless /^[a-zA-Z]+\// =~ selector
    return Result.new(
      query_handler: default_handler,
      selector: selector,
    )
  end

  chunk = selector.split("/")
  name = chunk.shift
  updated_selector = chunk.join("/")

  query_handler = query_handlers[name.to_sym]

  unless query_handler
    raise ArgumentError.new("Query set to use \"#{name}\", but no query handler of that name was found")
  end

  Result.new(
    query_handler: query_handler,
    selector: updated_selector,
  )
end

#query_handlersObject



6
7
8
9
10
# File 'lib/puppeteer/query_handler_manager.rb', line 6

def query_handlers
  @query_handlers ||= {
    aria: Puppeteer::AriaQueryHandler.new,
  }
end