Class: Superheroes
- Inherits:
-
Object
- Object
- Superheroes
- Defined in:
- lib/marvel_best_superheroes/superhero.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#aliases ⇒ Object
Returns the value of attribute aliases.
-
#biography ⇒ Object
Returns the value of attribute biography.
-
#birthday ⇒ Object
Returns the value of attribute birthday.
-
#charactertype ⇒ Object
Returns the value of attribute charactertype.
-
#gender ⇒ Object
Returns the value of attribute gender.
-
#name ⇒ Object
Returns the value of attribute name.
-
#powers ⇒ Object
Returns the value of attribute powers.
-
#realname ⇒ Object
Returns the value of attribute realname.
-
#supername ⇒ Object
Returns the value of attribute supername.
Class Method Summary collapse
Instance Method Summary collapse
- #allsites ⇒ Object
-
#initialize(name = nil, biography = nil, supername = nil, realname = nil, aliases = nil, gender = nil, charactertype = nil, birthday = nil, powers = nil) ⇒ Superheroes
constructor
A new instance of Superheroes.
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
#aliases ⇒ Object
Returns the value of attribute aliases.
8 9 10 |
# File 'lib/marvel_best_superheroes/superhero.rb', line 8 def aliases @aliases end |
#biography ⇒ Object
Returns the value of attribute biography.
8 9 10 |
# File 'lib/marvel_best_superheroes/superhero.rb', line 8 def biography @biography end |
#birthday ⇒ Object
Returns the value of attribute birthday.
8 9 10 |
# File 'lib/marvel_best_superheroes/superhero.rb', line 8 def birthday @birthday end |
#charactertype ⇒ Object
Returns the value of attribute charactertype.
8 9 10 |
# File 'lib/marvel_best_superheroes/superhero.rb', line 8 def charactertype @charactertype end |
#gender ⇒ Object
Returns the value of attribute gender.
8 9 10 |
# File 'lib/marvel_best_superheroes/superhero.rb', line 8 def gender @gender end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/marvel_best_superheroes/superhero.rb', line 8 def name @name end |
#powers ⇒ Object
Returns the value of attribute powers.
8 9 10 |
# File 'lib/marvel_best_superheroes/superhero.rb', line 8 def powers @powers end |
#realname ⇒ Object
Returns the value of attribute realname.
8 9 10 |
# File 'lib/marvel_best_superheroes/superhero.rb', line 8 def realname @realname end |
#supername ⇒ Object
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
.all ⇒ Object
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 |
.reset ⇒ Object
51 52 53 |
# File 'lib/marvel_best_superheroes/superhero.rb', line 51 def self.reset @@all = [] end |
Instance Method Details
#allsites ⇒ Object
25 26 27 |
# File 'lib/marvel_best_superheroes/superhero.rb', line 25 def allsites AllSuperheroes.all.map { |e| "#{BASEPATH}#{e.url}"} end |