Class: Mousecop::Player

Inherits:
Object
  • Object
show all
Defined in:
lib/mousecop/player.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#conferenceObject

Returns the value of attribute conference.



4
5
6
# File 'lib/mousecop/player.rb', line 4

def conference
  @conference
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/mousecop/player.rb', line 4

def id
  @id
end

#imageObject

Returns the value of attribute image.



4
5
6
# File 'lib/mousecop/player.rb', line 4

def image
  @image
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/mousecop/player.rb', line 4

def name
  @name
end

Class Method Details

.allObject



6
7
8
9
10
11
12
13
# File 'lib/mousecop/player.rb', line 6

def self.all
  data = PlayerSource.new.fetch_data('/players')
  data.collect do |player|
  self.create(name: player["name"],
  id: player["id"],
  image: player["image"])
  end
end

.create(attributes = {}) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/mousecop/player.rb', line 25

def self.create(attributes= {})
  self.new.tap do |player|
  player.name = attributes[:name]
  player.id = attributes[:id]
  player.image = attributes[:image]
  end
end

.firstObject



20
21
22
23
# File 'lib/mousecop/player.rb', line 20

def self.first
  @all ||= self.all
  @all.first
end

.sampleObject



15
16
17
18
# File 'lib/mousecop/player.rb', line 15

def self.sample
  player = PlayerSource.new.fetch_data('/player').first
  self.create(name: player["name"], id: player["id"], image: player["image"])
end