Class: MetacriticGames::Platform

Inherits:
Object
  • Object
show all
Extended by:
Concerns::Findable::ClassMethods, Concerns::Nameable::ClassMethods, Concerns::Persistable::ClassMethods
Includes:
Concerns::Persistable::InstanceMethods
Defined in:
lib/platform.rb

Constant Summary collapse

@@all =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Concerns::Nameable::ClassMethods

create

Methods included from Concerns::Findable::ClassMethods

find_by_name, find_or_create_by_name

Methods included from Concerns::Persistable::ClassMethods

destroy_all

Methods included from Concerns::Persistable::InstanceMethods

#save

Constructor Details

#initializePlatform

Returns a new instance of Platform.



16
17
18
# File 'lib/platform.rb', line 16

def initialize
  self.games = []
end

Instance Attribute Details

#gamesObject

Returns the value of attribute games.



8
9
10
# File 'lib/platform.rb', line 8

def games
  @games
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/platform.rb', line 8

def name
  @name
end

Class Method Details

.allObject



12
13
14
# File 'lib/platform.rb', line 12

def self.all
  @@all
end

.create_platforms(platform_array) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/platform.rb', line 20

def self.create_platforms(platform_array)
  platform_array.each do |platform|
    MetacriticGames::CLI.progressbar.increment
    self.find_or_create_by_name(platform)
  end
  self.all
end

Instance Method Details

#add_game(game) ⇒ Object



28
29
30
31
# File 'lib/platform.rb', line 28

def add_game(game)
  game.platform << self unless game.platform.include? self
  self.games << game unless self.games.include?(game)
end

#genresObject



33
34
35
# File 'lib/platform.rb', line 33

def genres
  self.games.collect {|game| game.genre}.uniq
end