Class: Loltierlist::Champion
- Inherits:
-
Object
- Object
- Loltierlist::Champion
- Defined in:
- lib/loltierlist/champion.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#role ⇒ Object
Returns the value of attribute role.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #champ_hash ⇒ Object
- #get_data ⇒ Object
-
#initialize(name, url, role) ⇒ Champion
constructor
A new instance of Champion.
- #print_data ⇒ Object
Constructor Details
#initialize(name, url, role) ⇒ Champion
Returns a new instance of Champion.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/loltierlist/champion.rb', line 7 def initialize(name, url, role) @name = name @url = url @role = role @champ_hash = { tier: nil, score: nil, win_rate: nil, role_rate: nil, pick_rate: nil, ban_rate: nil } @@all << self end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/loltierlist/champion.rb', line 4 def name @name end |
#role ⇒ Object
Returns the value of attribute role.
4 5 6 |
# File 'lib/loltierlist/champion.rb', line 4 def role @role end |
#url ⇒ Object
Returns the value of attribute url.
4 5 6 |
# File 'lib/loltierlist/champion.rb', line 4 def url @url end |
Class Method Details
.all ⇒ Object
22 23 24 |
# File 'lib/loltierlist/champion.rb', line 22 def self.all @@all end |
Instance Method Details
#champ_hash ⇒ Object
26 27 28 |
# File 'lib/loltierlist/champion.rb', line 26 def champ_hash @champ_hash end |
#get_data ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/loltierlist/champion.rb', line 30 def get_data doc = Nokogiri::HTML(open(@url)) count = 0 doc.css(".stats_table tr").each {|element| header = element.css("th").text data = element.css("td").text if data != nil && count < 8 # convert the header into symbol format to access hash, then set value to data header_sym = header.downcase.gsub(" ","_").chomp(":").to_sym champ_hash[header_sym] = data # i know i only want the first 7 fields for data count += 1 end } end |
#print_data ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/loltierlist/champion.rb', line 46 def print_data puts "\n\n\n#{@name} Champion Data" puts "-------------------------------------" puts "Role: #{@role}" puts "Tier: #{champ_hash[:tier]}" puts "Score: #{champ_hash[:score]}" puts "Win Rate: #{champ_hash[:win_rate]}" puts "Role Rate: #{champ_hash[:role_rate]}" puts "Pick Rate: #{champ_hash[:pick_rate]}" puts "Ban Rate: #{champ_hash[:ban_rate]}" puts "KDA Ratio: #{champ_hash[:kda_ratio]}" end |