Class: ExactSearcher

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

Instance Method Summary collapse

Constructor Details

#initializeExactSearcher



2
3
4
# File 'lib/exact_searcher.rb', line 2

def initialize
  @exiter = Exiter.new
end

Instance Method Details

#search(search_term, links) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/exact_searcher.rb', line 6

def search (search_term, links)
  # Grep the links array to exactly match our search term
  filtered_links = links.grep(/\/#{search_term}.html\"/i)

  # Handle error and return if we don't find anything
  if filtered_links.empty?
    @exiter.exit_due_to_doc_not_found
    return
  end

  # Get the relative URL of the required class
  relative_url = filtered_links[0].partition("link:\"").last.partition("\"").first

  # Append to base URL to form complete URL
  target_link = "#{Constants::BASE_URL}/#{relative_url}"

  return target_link
end