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



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

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



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

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