Class: AllSuperheroes

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

Constant Summary collapse

SITE =
"https://comicvine.gamespot.com/profile/noahmaximillion/lists/top-100-marvel-superheroes/48749/"
@@all =

array contains all superheroes information

[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, url = nil) ⇒ AllSuperheroes

Returns a new instance of AllSuperheroes.



14
15
16
17
18
# File 'lib/marvel_best_superheroes/allSuperheroes.rb', line 14

def initialize(name = nil, url = nil)
    @name = name
    @url = url
    @@all << self
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/marvel_best_superheroes/allSuperheroes.rb', line 7

def name
  @name
end

#urlObject

Returns the value of attribute url.



7
8
9
# File 'lib/marvel_best_superheroes/allSuperheroes.rb', line 7

def url
  @url
end

Class Method Details

.allObject



29
30
31
# File 'lib/marvel_best_superheroes/allSuperheroes.rb', line 29

def self.all
    @@all
end

.create_all_superheroesObject



21
22
23
24
25
26
27
# File 'lib/marvel_best_superheroes/allSuperheroes.rb', line 21

def self.create_all_superheroes
    Nokogiri::HTML(open(SITE)).css("ul.editorial").css("li").map do |hero|
        name = hero.css("h3").text
        url = hero.css("a").attribute("href").value
        self.new(name, url)
    end
end