class Phi::Losophy::Page

Attributes

connection[R]
term[R]

Public Class Methods

new(term, connection) click to toggle source
# File lib/phi/losophy/page.rb, line 7
def initialize(term, connection)
  @term       = term
  @connection = connection
end

Public Instance Methods

inspect() click to toggle source
# File lib/phi/losophy/page.rb, line 20
def inspect
  "#<#{self.class.name}:#{term}>"
end
next() click to toggle source
# File lib/phi/losophy/page.rb, line 16
def next
  @next ||= Page.new(next_term, connection)
end
next_term() click to toggle source
# File lib/phi/losophy/page.rb, line 24
def next_term
  Node.new(html.css(selector)).anchor.attr("href")[6..-1]
end
philosophy?() click to toggle source
# File lib/phi/losophy/page.rb, line 12
def philosophy?
  term.downcase == "philosophy"
end

Private Instance Methods

html() click to toggle source
# File lib/phi/losophy/page.rb, line 34
def html
  @html ||= Nokogiri::HTML(page)
end
page() click to toggle source
# File lib/phi/losophy/page.rb, line 38
def page
  @page ||= request.body
end
path() click to toggle source
# File lib/phi/losophy/page.rb, line 47
def path
  "/wiki/#{term}"
end
request() click to toggle source
# File lib/phi/losophy/page.rb, line 42
def request
  sleep 0.25 
  connection.get(path: path)
end
selector() click to toggle source
# File lib/phi/losophy/page.rb, line 30
def selector
  %q{#mw-content-text > p:first}# > a:first[href^='/wiki']}
end