mirror of
https://github.com/ryankazokas/turbovault-app.git
synced 2026-04-16 23:22:53 +00:00
Moving to github
This commit is contained in:
25
app/models/igdb_game.rb
Normal file
25
app/models/igdb_game.rb
Normal file
@@ -0,0 +1,25 @@
|
||||
class IgdbGame < ApplicationRecord
|
||||
# Associations
|
||||
has_many :igdb_match_suggestions
|
||||
has_many :games, foreign_key: :igdb_id, primary_key: :igdb_id
|
||||
|
||||
# Validations
|
||||
validates :igdb_id, presence: true, uniqueness: true
|
||||
validates :name, presence: true
|
||||
|
||||
# Scopes
|
||||
scope :popular, -> { order(match_count: :desc) }
|
||||
scope :recent, -> { order(last_synced_at: :desc) }
|
||||
|
||||
# Instance methods
|
||||
def increment_match_count!
|
||||
increment!(:match_count)
|
||||
end
|
||||
|
||||
def cover_image_url(size = "cover_big")
|
||||
return nil unless cover_url.present?
|
||||
# IGDB uses image IDs like "co1234"
|
||||
# We need to construct the full URL
|
||||
"https://images.igdb.com/igdb/image/upload/t_#{size}/#{cover_url}.jpg"
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user