Class: SL::StackOverflowSearch

Inherits:
Object
  • Object
show all
Defined in:
lib/searchlink/searches/stackoverflow.rb

Overview

Stack Overflow search

Class Method Summary collapse

Class Method Details

.search(search_type, search_terms, link_text) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/searchlink/searches/stackoverflow.rb', line 17

def search(search_type, search_terms, link_text)
  url, title, link_text = SL.ddg("site:stackoverflow.com #{search_terms}", link_text)
  link_text = title if link_text == '' && !SL.titleize

  if search_type =~ /a$/
    body = `curl -SsL #{url}`.strip
    m = body.match(/id="(?<id>answer-\d+)"[^>]+accepted-answer/)
    url = "#{url}##{m['id']}" if m
  end

  [url, title, link_text]
end

.settingsObject



7
8
9
10
11
12
13
14
15
# File 'lib/searchlink/searches/stackoverflow.rb', line 7

def settings
  {
    trigger: 'soa?',
    searches: [
      ['so', 'StackOverflow Search'],
      ['soa', 'StackOverflow Accepted Answer']
    ]
  }
end