class Hogwarts::Textbooks
Attributes
name[RW]
url[RW]
Public Class Methods
all()
click to toggle source
# File lib/textbooks.rb, line 30 def self.all @@all end
new(name, url)
click to toggle source
# File lib/textbooks.rb, line 10 def initialize(name, url) @name = name @url = url @@all << self end
scrape_textbooks()
click to toggle source
# File lib/textbooks.rb, line 16 def self.scrape_textbooks textbooks = [] doc = Nokogiri::HTML(open("https://www.hp-lexicon.org/list/books/textbooks/")) info = doc.css(".col-md-12 ul li a") info.each do |n| textbook = {} textbook[:name] = n.text textbook[:url] = n.attr("href") textbooks << textbook end textbooks end