Class: QDB::QdbUS

Inherits:
Base
  • Object
show all
Defined in:
lib/cinch/plugins/qdb/qdbus.rb

Overview

Inheriting Base

Instance Attribute Summary

Attributes inherited from Base

#id_path_template, #latest_path, #name, #random_path, #shortname, #url

Instance Method Summary collapse

Constructor Details

#initializeQdbUS

attr_reader :name, :shortname, :url, :id_path_template, :random_path, :latest_path


8
9
10
11
12
# File 'lib/cinch/plugins/qdb/qdbus.rb', line 8

def initialize
  @name, @shortname, @url = "Qdb.us", "us", "http://qdb.us/"
  @id_path_template = "%<id>s"
  @random_path = "random"
end

Instance Method Details

#by_id(id) ⇒ Object

Raises:


14
15
16
17
18
19
# File 'lib/cinch/plugins/qdb/qdbus.rb', line 14

def by_id(id)
  o = Nokogiri::HTML(open(@url + (@id_path_template % {id: id})))
  raise QDB::Error::QuoteNotFound.new(id), "Quote ##{id} does not exist." if o.at(".qt").nil?
  quotes = CGI.unescape_html o.at(".qt").children.to_s.gsub(/[\r\n]/,"")
  Quote.new(id, quotes.split(/<br *\/?>/i))
end

#latestObject


25
26
27
# File 'lib/cinch/plugins/qdb/qdbus.rb', line 25

def latest
  self.by_id(get_first_id(@url))
end

#randomObject


21
22
23
# File 'lib/cinch/plugins/qdb/qdbus.rb', line 21

def random
  self.by_id(get_first_id(@url + @random_path))
end