Class: Mousecop::Player
- Inherits:
-
Object
- Object
- Mousecop::Player
- Defined in:
- lib/mousecop/player.rb
Instance Attribute Summary collapse
-
#conference ⇒ Object
Returns the value of attribute conference.
-
#id ⇒ Object
Returns the value of attribute id.
-
#image ⇒ Object
Returns the value of attribute image.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Attribute Details
#conference ⇒ Object
Returns the value of attribute conference.
6 7 8 |
# File 'lib/mousecop/player.rb', line 6 def conference @conference end |
#id ⇒ Object
Returns the value of attribute id.
6 7 8 |
# File 'lib/mousecop/player.rb', line 6 def id @id end |
#image ⇒ Object
Returns the value of attribute image.
6 7 8 |
# File 'lib/mousecop/player.rb', line 6 def image @image end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/mousecop/player.rb', line 6 def name @name end |
Class Method Details
.all ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/mousecop/player.rb', line 8 def self.all @roster = Faraday.get(base_url + "/players").body JSON.parse(@roster).collect do |player| self.create(name: player["name"], id: player["id"], image: player["image"]) end end |
.base_url ⇒ Object
39 40 41 |
# File 'lib/mousecop/player.rb', line 39 def self.base_url "http://collegebowl.avatarpro.biz/" end |
.create(attributes = {}) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/mousecop/player.rb', line 18 def self.create(attributes= {}) self.new.tap do |player| player.name = attributes[:name] player.id = attributes[:id] player.image = attributes[:image] end end |
.first ⇒ Object
34 35 36 37 |
# File 'lib/mousecop/player.rb', line 34 def self.first @all ||= self.all @all.first end |
.sample ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/mousecop/player.rb', line 26 def self.sample player_response = Faraday.get(base_url + "/player").body player = JSON.parse(player_response).first Mousecop::Player.create(name: player["name"], id: player["id"], image: player["image"]) end |