Class: Hogwarts::Textbooks

Inherits:
Object
  • Object
show all
Defined in:
lib/textbooks.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/textbooks.rb', line 5

def name
  @name
end

#urlObject

Returns the value of attribute url.



5
6
7
# File 'lib/textbooks.rb', line 5

def url
  @url
end

Class Method Details

.allObject



30
31
32
# File 'lib/textbooks.rb', line 30

def self.all
    @@all
end

.scrape_textbooksObject



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