Class: Superheroes

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

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, biography = nil, supername = nil, realname = nil, aliases = nil, gender = nil, charactertype = nil, birthday = nil, powers = nil) ⇒ Superheroes

Returns a new instance of Superheroes.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/marvel_best_superheroes/superhero.rb', line 12

def initialize(name = nil, biography = nil, supername = nil, realname = nil, aliases = nil, gender = nil, charactertype = nil, birthday = nil, powers = nil)
    @name = name
    @biography = biography
    @supername = supername
    @realname = realname
    @aliases = aliases
    @gender = gender
    @charactertype = charactertype
    @birthday = birthday
    @powers = powers
    @@all << self
end

Instance Attribute Details

#aliasesObject

Returns the value of attribute aliases.



8
9
10
# File 'lib/marvel_best_superheroes/superhero.rb', line 8

def aliases
  @aliases
end

#biographyObject

Returns the value of attribute biography.



8
9
10
# File 'lib/marvel_best_superheroes/superhero.rb', line 8

def biography
  @biography
end

#birthdayObject

Returns the value of attribute birthday.



8
9
10
# File 'lib/marvel_best_superheroes/superhero.rb', line 8

def birthday
  @birthday
end

#charactertypeObject

Returns the value of attribute charactertype.



8
9
10
# File 'lib/marvel_best_superheroes/superhero.rb', line 8

def charactertype
  @charactertype
end

#genderObject

Returns the value of attribute gender.



8
9
10
# File 'lib/marvel_best_superheroes/superhero.rb', line 8

def gender
  @gender
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/marvel_best_superheroes/superhero.rb', line 8

def name
  @name
end

#powersObject

Returns the value of attribute powers.



8
9
10
# File 'lib/marvel_best_superheroes/superhero.rb', line 8

def powers
  @powers
end

#realnameObject

Returns the value of attribute realname.



8
9
10
# File 'lib/marvel_best_superheroes/superhero.rb', line 8

def realname
  @realname
end

#supernameObject

Returns the value of attribute supername.



8
9
10
# File 'lib/marvel_best_superheroes/superhero.rb', line 8

def supername
  @supername
end

Class Method Details

.allObject



47
48
49
# File 'lib/marvel_best_superheroes/superhero.rb', line 47

def self.all
    @@all
end

.get_superhero_infos(site) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/marvel_best_superheroes/superhero.rb', line 29

def self.get_superhero_infos(site)

    Superheroes.reset

    doc = Nokogiri::HTML(open(site)).css("table.table tbody")
    name = Nokogiri::HTML(open(site)).css("h1").text.strip
    biography = Nokogiri::HTML(open(site)).css("h3.display-view").text
    supername = doc.css("div[data-field='realName']").text.strip.split(/\n/).first
    aliases = doc.css("div[data-field='aliases']").text.strip.split("\r\n").map{|i| "\n                      #{i}"}.join
    realname = doc.css("div[data-field='realName']").text.strip.split(/\n/).last.strip
    gender = doc.css("div[data-field='gender']").text.strip
    charactertype = doc.css("div[data-field='origin']").text.strip
    birthday = doc.css("div[data-field='birthday']").text.strip
    powers = doc.css("div[data-field='powers']").text
            
    self.new(name, biography, supername, realname, aliases, gender, charactertype, birthday, powers)
end

.resetObject



51
52
53
# File 'lib/marvel_best_superheroes/superhero.rb', line 51

def self.reset
    @@all = []
end

Instance Method Details

#allsitesObject



25
26
27
# File 'lib/marvel_best_superheroes/superhero.rb', line 25

def allsites
    AllSuperheroes.all.map { |e|  "#{BASEPATH}#{e.url}"}
end