Class: Loltierlist::TierList
- Inherits:
-
Object
- Object
- Loltierlist::TierList
- Defined in:
- lib/loltierlist/tierlist.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#tier_hash ⇒ Object
readonly
Returns the value of attribute tier_hash.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name) ⇒ TierList
constructor
A new instance of TierList.
- #print_tier ⇒ Object
- #roles ⇒ Object
Constructor Details
#initialize(name) ⇒ TierList
Returns a new instance of TierList.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/loltierlist/tierlist.rb', line 8 def initialize(name) @roles = { MID: [], JUNGLE: [], ADC: [], TOP: [], SUPPORT: [] } @name = name @@all << self end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/loltierlist/tierlist.rb', line 5 def name @name end |
#tier_hash ⇒ Object (readonly)
Returns the value of attribute tier_hash.
5 6 7 |
# File 'lib/loltierlist/tierlist.rb', line 5 def tier_hash @tier_hash end |
Class Method Details
.all ⇒ Object
24 25 26 |
# File 'lib/loltierlist/tierlist.rb', line 24 def self.all @@all end |
.get_tier(tier) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/loltierlist/tierlist.rb', line 28 def self.get_tier(tier) doc = Nokogiri::HTML(open("http://www.metasrc.com/na/5v5/tierlist")) if doc.css("#" + tier + ".tier .rig a").length > 0 tierlist = Loltierlist::TierList.new(tier) # fill in tier data doc.css("#" + tier + ".tier .rig a").each {|champ| champurl = "http://www.metasrc.com" + champ["href"] champ_id = champ.css("li").first champ_data = champ_id["id"].split("-") # get role of champ role = champ_data[1].to_sym # create new champ object new_champ = Loltierlist::Champion.new(champ_data[0], champurl, role.to_s) # add champ to that role tierlist.roles[role] << new_champ } return tierlist else puts "That tier doesn't exist for the site this CLI uses!" end end |
Instance Method Details
#print_tier ⇒ Object
50 51 52 53 54 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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/loltierlist/tierlist.rb', line 50 def print_tier puts "\n\n" puts self.name + " Tier" puts "****************************" print "Mid: " @roles[:MID].each {|champ| if champ.name != @roles[:MID][-1].name print "#{champ.name}, " else print "#{champ.name}" end } print "\nJungle: " @roles[:JUNGLE].each {|champ| if champ.name != @roles[:JUNGLE][-1].name print "#{champ.name}, " else print "#{champ.name}" end } print "\nADC: " @roles[:ADC].each {|champ| if champ.name != @roles[:ADC][-1].name print "#{champ.name}, " else print "#{champ.name}" end } print "\nTop: " @roles[:TOP].each {|champ| if champ.name != @roles[:TOP][-1].name print "#{champ.name}, " else print "#{champ.name}" end } print "\nSupport: " @roles[:SUPPORT].each {|champ| if champ.name != @roles[:SUPPORT][-1].name print "#{champ.name}, " else print "#{champ.name}" end } print "\n\n" end |
#roles ⇒ Object
20 21 22 |
# File 'lib/loltierlist/tierlist.rb', line 20 def roles @roles end |