Class: Hero
- Inherits:
-
Object
- Object
- Hero
- Defined in:
- lib/ow_heroes_roster/hero.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#abilities ⇒ Object
Returns the value of attribute abilities.
-
#biography ⇒ Object
Returns the value of attribute biography.
-
#name ⇒ Object
Returns the value of attribute name.
-
#overview ⇒ Object
Returns the value of attribute overview.
-
#path ⇒ Object
Returns the value of attribute path.
-
#quote ⇒ Object
Returns the value of attribute quote.
-
#role ⇒ Object
Returns the value of attribute role.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#display_information ⇒ Object
display hero details.
-
#get_details(index_url) ⇒ Object
get details by scraping hero page.
-
#initialize(name, path) ⇒ Hero
constructor
A new instance of Hero.
Constructor Details
#initialize(name, path) ⇒ Hero
Returns a new instance of Hero.
11 12 13 14 15 |
# File 'lib/ow_heroes_roster/hero.rb', line 11 def initialize(name, path) @name = name @url = "https://playoverwatch.com#{path}" @@all << self end |
Instance Attribute Details
#abilities ⇒ Object
Returns the value of attribute abilities.
7 8 9 |
# File 'lib/ow_heroes_roster/hero.rb', line 7 def abilities @abilities end |
#biography ⇒ Object
Returns the value of attribute biography.
7 8 9 |
# File 'lib/ow_heroes_roster/hero.rb', line 7 def biography @biography end |
#name ⇒ Object
Returns the value of attribute name.
7 8 9 |
# File 'lib/ow_heroes_roster/hero.rb', line 7 def name @name end |
#overview ⇒ Object
Returns the value of attribute overview.
7 8 9 |
# File 'lib/ow_heroes_roster/hero.rb', line 7 def overview @overview end |
#path ⇒ Object
Returns the value of attribute path.
7 8 9 |
# File 'lib/ow_heroes_roster/hero.rb', line 7 def path @path end |
#quote ⇒ Object
Returns the value of attribute quote.
7 8 9 |
# File 'lib/ow_heroes_roster/hero.rb', line 7 def quote @quote end |
#role ⇒ Object
Returns the value of attribute role.
7 8 9 |
# File 'lib/ow_heroes_roster/hero.rb', line 7 def role @role end |
#url ⇒ Object
Returns the value of attribute url.
7 8 9 |
# File 'lib/ow_heroes_roster/hero.rb', line 7 def url @url end |
Class Method Details
.all ⇒ Object
81 82 83 |
# File 'lib/ow_heroes_roster/hero.rb', line 81 def self.all @@all end |
.find_by_name(name) ⇒ Object
17 18 19 |
# File 'lib/ow_heroes_roster/hero.rb', line 17 def self.find_by_name(name) self.all.find{|hero| hero.name == name} end |
Instance Method Details
#display_information ⇒ Object
display hero details
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/ow_heroes_roster/hero.rb', line 55 def display_information get_details(url) puts "\n--------------------------------".colorize(:yellow) print "\n**".colorize(:magenta) print " #{self.name.upcase}".colorize(:white) puts " **".colorize(:magenta) puts "\n--------------------------------".colorize(:yellow) puts "\nROLE: #{self.role}".colorize(:yellow) puts "--------------------------------".colorize(:magenta) puts "OVERVIEW:".colorize(:yellow) puts "#{self.overview}".colorize(:white) puts "--------------------------------".colorize(:magenta) puts "ABILITIES:\n".colorize(:yellow) self.abilities.each do |ability| puts "*#{ability[:ability]}: #{ability[:description]}".colorize(:white) end puts "--------------------------------".colorize(:magenta) puts "BIOGRAPHY:\n".colorize(:yellow) self.biography.each_value {|value| puts "\t*#{value}".colorize(:white) } puts "\n--------------------------------".colorize(:magenta) if self.quote != "" puts "QUOTE: #{self.quote}".colorize(:yellow) puts "--------------------------------".colorize(:magenta) end end |
#get_details(index_url) ⇒ Object
get details by scraping hero page
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/ow_heroes_roster/hero.rb', line 22 def get_details(index_url) html = open(index_url) doc = Nokogiri::HTML(html) #role @role = doc.css(".hero-detail-role-name").text #overview @overview = doc.css("#overview .hero-detail-description").text #abilities @abilities = [] doc.css(".hero-ability").each do |ability| hero_ability = ability.css(".hero-ability-descriptor .h5").text hero_description = ability.css(".hero-ability-descriptor p").text @abilities << {ability: hero_ability, description: hero_description} end #biography @biography = {} doc.css("#story .hero-bio").each do |info| hero_real_name = info.css(".name .hero-bio-copy").text hero_occupation = info.css(".occupation .hero-bio-copy").text hero_base = info.css(".base .hero-bio-copy").text hero_affiliation = info.css(".affiliation").text @biography = {real_name: hero_real_name, occupation: hero_occupation, base: hero_base, affiliation: hero_affiliation} end #quote @quote = doc.css("#story p.h4").text end |