class Lita::Handlers::Howlongtobeat::HowlongtobeatSearch
Constants
- SEARCH_URL
- SITE_URL
Public Class Methods
new(term, client = Faraday)
click to toggle source
# File lib/lita/handlers/howlongtobeat.rb, line 15 def initialize(term, client = Faraday) @term = term @client = client end
Public Instance Methods
doc()
click to toggle source
# 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)
click to toggle source
# 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()
click to toggle source
# File lib/lita/handlers/howlongtobeat.rb, line 27 def story text = doc.css(".search_list_tidbit.center")[0].text text == '--' ? nil : text end
title()
click to toggle source
# File lib/lita/handlers/howlongtobeat.rb, line 32 def title doc.css('a')[0] end
title_content()
click to toggle source
# File lib/lita/handlers/howlongtobeat.rb, line 40 def title_content title ? title.attr('title') : nil end
title_href()
click to toggle source
# File lib/lita/handlers/howlongtobeat.rb, line 36 def title_href title ? title.attr('href') : nil end