class Bgg::Game

Attributes

alternate_names[R]
artists[R]
categories[R]
description[R]
designers[R]
families[R]
id[R]
image[R]
max_players[R]
mechanics[R]
min_players[R]
name[R]
names[R]
playing_time[R]
publishers[R]
thumbnail[R]
year_published[R]

Public Class Methods

find_by_id(game_id) click to toggle source
# File lib/bgg/game.rb, line 34
def self.find_by_id(game_id)
  game_id = Integer(game_id)
  if game_id < 1
    raise ArgumentError.new('game_id must be greater than 0!')
  end

  game_data = BggApi.thing({id: game_id, type: 'boardgame'})
  unless game_data.has_key?('item')
    raise ArgumentError.new('Game does not exist')
  end
  game_data = game_data['item'][0]

  Game.new(game_data)
end
new(game_data) click to toggle source
# File lib/bgg/game.rb, line 10
def initialize(game_data)
  @game_data = game_data

  @id = game_data['id'].to_i
  @names = game_data['name'].map{ |n| n['value'] }
  @name = game_data['name'].find{ |n| n.fetch('type', '') == 'primary'}['value']

  @alternate_names = @names.reject{ |name| name == @name }
  @artists = filter_links_for('boardgameartist')
  @categories = filter_links_for('boardgamecategory')
  @description = game_data['description'][0]
  @designers = filter_links_for('boardgamedesigner')
  @families = filter_links_for('boardgamefamily')
  @image = game_data['image'][0]
  @max_players = game_data['maxplayers'][0]['value'].to_i
  @mechanics = filter_links_for('boardgamemechanic')
  @min_players = game_data['minplayers'][0]['value'].to_i
  @playing_time = game_data['playingtime'][0]['value'].to_i
  @publishers = filter_links_for('boardgamepublisher')
  @recommended_minimum_age = game_data['minage'][0]['value'].to_i
  @thumbnail = game_data['thumbnail'][0]
  @year_published = game_data['yearpublished'][0]['value'].to_i
end

Private Instance Methods