Class: Lita::Handlers::Howlongtobeat::HowlongtobeatSearch
- Inherits:
-
Object
- Object
- Lita::Handlers::Howlongtobeat::HowlongtobeatSearch
- Defined in:
- lib/lita/handlers/howlongtobeat.rb
Constant Summary collapse
- SEARCH_URL =
"https://howlongtobeat.com/search_main.php?page=1"
- SITE_URL =
"https://howlongtobeat.com"
Instance Method Summary collapse
- #doc ⇒ Object
-
#initialize(term, client = Faraday) ⇒ HowlongtobeatSearch
constructor
A new instance of HowlongtobeatSearch.
- #print_result(response) ⇒ Object
- #story ⇒ Object
- #title ⇒ Object
- #title_content ⇒ Object
- #title_href ⇒ Object
Constructor Details
#initialize(term, client = Faraday) ⇒ HowlongtobeatSearch
Returns a new instance of HowlongtobeatSearch.
15 16 17 18 |
# File 'lib/lita/handlers/howlongtobeat.rb', line 15 def initialize(term, client = Faraday) @term = term @client = client end |
Instance Method Details
#doc ⇒ Object
44 45 46 47 48 49 |
# File 'lib/lita/handlers/howlongtobeat.rb', line 44 def doc @data ||= begin search = @client.post(SEARCH_URL, queryString: @term, t: 'games', sorthead: 'popular', sortd: 'Normal Order', detail: '0') Nokogiri::HTML(search.body) end end |
#print_result(response) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/lita/handlers/howlongtobeat.rb', line 20 def print_result(response) response.reply("No results found for #{@term}") && return unless title response.reply("No data found for how long it will take to complete the main story of '#{title_content}'") && return unless story response.reply("It will take about #{story}to beat the main story of '#{title_content}'") response.reply("Source: #{SITE_URL}/#{title_href}") end |
#story ⇒ Object
27 28 29 30 |
# File 'lib/lita/handlers/howlongtobeat.rb', line 27 def story text = doc.css(".search_list_tidbit.center")[0].text text == '--' ? nil : text end |
#title ⇒ Object
32 33 34 |
# File 'lib/lita/handlers/howlongtobeat.rb', line 32 def title doc.css('a')[0] end |
#title_content ⇒ Object
40 41 42 |
# File 'lib/lita/handlers/howlongtobeat.rb', line 40 def title_content title ? title.attr('title') : nil end |
#title_href ⇒ Object
36 37 38 |
# File 'lib/lita/handlers/howlongtobeat.rb', line 36 def title_href title ? title.attr('href') : nil end |