Class: MetacriticGames::Game
- Inherits:
-
Object
- Object
- MetacriticGames::Game
- Extended by:
- Concerns::Findable::ClassMethods, Concerns::Nameable::ClassMethods, Concerns::Persistable::ClassMethods
- Includes:
- Concerns::Persistable::InstanceMethods
- Defined in:
- lib/game.rb
Constant Summary collapse
- @@all =
[]
Instance Attribute Summary collapse
-
#genre ⇒ Object
Returns the value of attribute genre.
-
#metascore ⇒ Object
Returns the value of attribute metascore.
-
#name ⇒ Object
Returns the value of attribute name.
-
#platform ⇒ Object
Returns the value of attribute platform.
-
#url ⇒ Object
Returns the value of attribute url.
-
#user_score ⇒ Object
Returns the value of attribute user_score.
Class Method Summary collapse
- .all ⇒ Object
-
.create_games(game_array) ⇒ Object
creates the game object based on the array passed in from the controller.
-
.score_by_platform(game, platform) ⇒ Object
changes the key of the metacritic and user scores from the generic “:platform” to a unique platform.name key required for multiplatform releases.
Instance Method Summary collapse
- #add_genre(genre) ⇒ Object
- #add_platform(platform) ⇒ Object
-
#initialize ⇒ Game
constructor
A new instance of Game.
Methods included from Concerns::Nameable::ClassMethods
Methods included from Concerns::Findable::ClassMethods
find_by_name, find_or_create_by_name
Methods included from Concerns::Persistable::ClassMethods
Methods included from Concerns::Persistable::InstanceMethods
Constructor Details
#initialize ⇒ Game
Returns a new instance of Game.
16 17 18 19 20 21 22 |
# File 'lib/game.rb', line 16 def initialize self.platform = [] self.url = {} self.genre = [] self. = {} self.user_score = {} end |
Instance Attribute Details
#genre ⇒ Object
Returns the value of attribute genre.
8 9 10 |
# File 'lib/game.rb', line 8 def genre @genre end |
#metascore ⇒ Object
Returns the value of attribute metascore.
8 9 10 |
# File 'lib/game.rb', line 8 def @metascore end |
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/game.rb', line 8 def name @name end |
#platform ⇒ Object
Returns the value of attribute platform.
8 9 10 |
# File 'lib/game.rb', line 8 def platform @platform end |
#url ⇒ Object
Returns the value of attribute url.
8 9 10 |
# File 'lib/game.rb', line 8 def url @url end |
#user_score ⇒ Object
Returns the value of attribute user_score.
8 9 10 |
# File 'lib/game.rb', line 8 def user_score @user_score end |
Class Method Details
.all ⇒ Object
12 13 14 |
# File 'lib/game.rb', line 12 def self.all @@all end |
.create_games(game_array) ⇒ Object
creates the game object based on the array passed in from the controller. once the game is created, it scrapes it calls the scraper to scrape it’s platform-specific page, then assigns the values and creates genre objects based off scrape data
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 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 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/game.rb', line 35 def self.create_games(game_array) game_array.each do |game| MetacriticGames::CLI..increment if game[:platform] == "XONE" #metacritic naming for the xboxone does not follow standard pattern platform = MetacriticGames::Platform.all.find {|platform| platform.name == "Xbox One"} game.tap do |new_game| new_game = self.find_or_create_by_name(game[:name]) new_game.add_platform(platform) new_game.url[:"#{game[:platform]}"] = game[:url] MetacriticGames::Scraper.scrape_game(new_game.url[:XONE]).each do |key,value| if value.is_a? Array value.each do |genre| new_genre = MetacriticGames::Genre.create_genre(genre) new_game.add_genre(new_genre) end elsif value.fetch(:platform) == "tbd" value[:platform] = "currently unavailable" new_game.send(("#{key}="), value) elsif value.fetch(:platform) == "" value[:platform] = "currently unavailable" new_game.send(("#{key}="), value) else new_game.send(("#{key}="), value) end end score_by_platform(new_game, platform) end elsif game[:platform] == "WIIU" #metacritic naming for the wii u does not follow standard pattern platform = MetacriticGames::Platform.all.find {|platform| platform.name == "Wii U"} game.tap do |new_game| new_game = self.find_or_create_by_name(game[:name]) new_game.add_platform(platform) new_game.url[:"#{game[:platform]}"] = game[:url] MetacriticGames::Scraper.scrape_game(new_game.url[:WIIU]).each do |key,value| if value.is_a? Array value.each do |genre| new_genre = MetacriticGames::Genre.create_genre(genre) new_game.add_genre(new_genre) end elsif value.fetch(:platform) == "tbd" value[:platform] = "currently unavailable" new_game.send(("#{key}="), value) elsif value.fetch(:platform) == "" value[:platform] = "currently unavailable" new_game.send(("#{key}="), value) else new_game.send(("#{key}="), value) end end score_by_platform(new_game, platform) end elsif game[:platform] == "VITA" #metacritic naming for the ps vita does not follow standard pattern platform = MetacriticGames::Platform.all.find {|platform| platform.name == "PS Vita"} game.tap do |new_game| new_game = self.find_or_create_by_name(game[:name]) new_game.add_platform(platform) new_game.url[:"#{game[:platform]}"] = game[:url] MetacriticGames::Scraper.scrape_game(new_game.url[:VITA]).each do |key,value| if value.is_a? Array value.each do |genre| new_genre = MetacriticGames::Genre.create_genre(genre) new_game.add_genre(new_genre) end elsif value.fetch(:platform) == "tbd" value[:platform] = "currently unavailable" new_game.send(("#{key}="), value) elsif value.fetch(:platform) == "" value[:platform] = "currently unavailable" new_game.send(("#{key}="), value) else new_game.send(("#{key}="), value) end end score_by_platform(new_game, platform) end else platform = MetacriticGames::Platform.all.find {|platform| platform.name == game[:platform]} game.tap do |new_game| new_game = self.find_or_create_by_name(game[:name]) new_game.add_platform(platform) new_game.url[:"#{game[:platform]}"] = game[:url] MetacriticGames::Scraper.scrape_game(new_game.url[:"#{platform.name}"]).each do |key,value| if value.is_a? Array value.each do |genre| new_genre = MetacriticGames::Genre.create_genre(genre) new_game.add_genre(new_genre) end elsif value.fetch(:platform) == "tbd" value[:platform] = "currently unavailable" new_game.send(("#{key}="), value) elsif value.fetch(:platform) == "" value[:platform] = "currently unavailable" new_game.send(("#{key}="), value) else new_game.send(("#{key}="), value) end end score_by_platform(new_game, platform) end end end end |
.score_by_platform(game, platform) ⇒ Object
changes the key of the metacritic and user scores from the generic “:platform” to a unique platform.name key required for multiplatform releases
143 144 145 146 |
# File 'lib/game.rb', line 143 def self.score_by_platform(game, platform) game.[platform.name.to_sym] = game..delete(:platform) game.user_score[platform.name.to_sym] = game.user_score.delete(:platform) end |
Instance Method Details
#add_genre(genre) ⇒ Object
29 30 31 32 |
# File 'lib/game.rb', line 29 def add_genre(genre) genre.add_game(self) unless genre.games.include?(self) self.genre << genre unless self.genre.include?(genre) end |
#add_platform(platform) ⇒ Object
24 25 26 27 |
# File 'lib/game.rb', line 24 def add_platform(platform) platform.add_game(self) unless platform.games.include?(self) self.platform << platform unless self.platform.include?(platform) end |