Class: Hogwarts::Atlas

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, url) ⇒ Atlas

Returns a new instance of Atlas.



10
11
12
13
14
# File 'lib/atlas.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/atlas.rb', line 5

def name
  @name
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

Class Method Details

.allObject



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

def self.all
    @@all
end

.scrape_atlasObject



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/atlas.rb', line 16

def self.scrape_atlas
    maps = []
    doc = Nokogiri::HTML(open("https://www.hp-lexicon.org/list/wizarding-atlas/atlas-of-hogwarts/"))
    info = doc.css(".col-md-12 ul li a")
    info.each do |n|
        atlas = {}
        atlas[:name] = n.text
        atlas[:url] = n.attr("href")
        maps << atlas

    end
    maps
end