Class: Hogwarts::Textbooks
- Inherits:
-
Object
- Object
- Hogwarts::Textbooks
- Defined in:
- lib/textbooks.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, url) ⇒ Textbooks
constructor
A new instance of Textbooks.
Constructor Details
#initialize(name, url) ⇒ Textbooks
Returns a new instance of Textbooks.
10 11 12 13 14 |
# File 'lib/textbooks.rb', line 10 def initialize(name, url) @name = name @url = url @@all << self end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/textbooks.rb', line 5 def name @name end |
#url ⇒ Object
Returns the value of attribute url.
5 6 7 |
# File 'lib/textbooks.rb', line 5 def url @url end |
Class Method Details
.all ⇒ Object
30 31 32 |
# File 'lib/textbooks.rb', line 30 def self.all @@all end |
.scrape_textbooks ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# 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 |