mirror of
https://github.com/ryankazokas/turbovault-app.git
synced 2026-04-17 02:52:55 +00:00
Moving to github
This commit is contained in:
54
app/models/igdb_platform_mapping.rb
Normal file
54
app/models/igdb_platform_mapping.rb
Normal file
@@ -0,0 +1,54 @@
|
||||
class IgdbPlatformMapping < ApplicationRecord
|
||||
# Associations
|
||||
belongs_to :platform
|
||||
|
||||
# Validations
|
||||
validates :platform_id, presence: true
|
||||
validates :igdb_platform_id, presence: true, uniqueness: { scope: :platform_id }
|
||||
|
||||
# Class methods
|
||||
def self.igdb_id_for_platform(platform)
|
||||
find_by(platform: platform)&.igdb_platform_id
|
||||
end
|
||||
|
||||
def self.seed_common_mappings!
|
||||
mappings = {
|
||||
"Nintendo 64" => 4,
|
||||
"PlayStation" => 7,
|
||||
"PlayStation 2" => 8,
|
||||
"PlayStation 3" => 9,
|
||||
"PlayStation 4" => 48,
|
||||
"PlayStation 5" => 167,
|
||||
"Xbox" => 11,
|
||||
"Xbox 360" => 12,
|
||||
"Xbox One" => 49,
|
||||
"Xbox Series X/S" => 169,
|
||||
"Nintendo Switch" => 130,
|
||||
"Wii" => 5,
|
||||
"Wii U" => 41,
|
||||
"GameCube" => 21,
|
||||
"Super Nintendo Entertainment System" => 19,
|
||||
"Nintendo Entertainment System" => 18,
|
||||
"Game Boy" => 33,
|
||||
"Game Boy Color" => 22,
|
||||
"Game Boy Advance" => 24,
|
||||
"Nintendo DS" => 20,
|
||||
"Nintendo 3DS" => 37,
|
||||
"PC" => 6,
|
||||
"Sega Genesis" => 29,
|
||||
"Sega Dreamcast" => 23,
|
||||
"PlayStation Portable" => 38,
|
||||
"PlayStation Vita" => 46
|
||||
}
|
||||
|
||||
mappings.each do |platform_name, igdb_id|
|
||||
platform = Platform.find_by(name: platform_name)
|
||||
next unless platform
|
||||
|
||||
find_or_create_by!(platform: platform) do |mapping|
|
||||
mapping.igdb_platform_id = igdb_id
|
||||
mapping.igdb_platform_name = platform_name
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user