Class: Bgg::Game
- Inherits:
-
Object
- Object
- Bgg::Game
- Defined in:
- lib/bgg/game.rb
Instance Attribute Summary collapse
-
#alternate_names ⇒ Object
readonly
Returns the value of attribute alternate_names.
-
#artists ⇒ Object
readonly
Returns the value of attribute artists.
-
#categories ⇒ Object
readonly
Returns the value of attribute categories.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#designers ⇒ Object
readonly
Returns the value of attribute designers.
-
#families ⇒ Object
readonly
Returns the value of attribute families.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#image ⇒ Object
readonly
Returns the value of attribute image.
-
#max_players ⇒ Object
readonly
Returns the value of attribute max_players.
-
#mechanics ⇒ Object
readonly
Returns the value of attribute mechanics.
-
#min_players ⇒ Object
readonly
Returns the value of attribute min_players.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#names ⇒ Object
readonly
Returns the value of attribute names.
-
#playing_time ⇒ Object
readonly
Returns the value of attribute playing_time.
-
#publishers ⇒ Object
readonly
Returns the value of attribute publishers.
-
#recommended_minimum_age ⇒ Object
readonly
Returns the value of attribute recommended_minimum_age.
-
#thumbnail ⇒ Object
readonly
Returns the value of attribute thumbnail.
-
#year_published ⇒ Object
readonly
Returns the value of attribute year_published.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(game_data) ⇒ Game
constructor
A new instance of Game.
Constructor Details
#initialize(game_data) ⇒ Game
Returns a new instance of Game.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# 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 |
Instance Attribute Details
#alternate_names ⇒ Object (readonly)
Returns the value of attribute alternate_names.
3 4 5 |
# File 'lib/bgg/game.rb', line 3 def alternate_names @alternate_names end |
#artists ⇒ Object (readonly)
Returns the value of attribute artists.
3 4 5 |
# File 'lib/bgg/game.rb', line 3 def artists @artists end |
#categories ⇒ Object (readonly)
Returns the value of attribute categories.
3 4 5 |
# File 'lib/bgg/game.rb', line 3 def categories @categories end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
3 4 5 |
# File 'lib/bgg/game.rb', line 3 def description @description end |
#designers ⇒ Object (readonly)
Returns the value of attribute designers.
3 4 5 |
# File 'lib/bgg/game.rb', line 3 def designers @designers end |
#families ⇒ Object (readonly)
Returns the value of attribute families.
3 4 5 |
# File 'lib/bgg/game.rb', line 3 def families @families end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/bgg/game.rb', line 3 def id @id end |
#image ⇒ Object (readonly)
Returns the value of attribute image.
3 4 5 |
# File 'lib/bgg/game.rb', line 3 def image @image end |
#max_players ⇒ Object (readonly)
Returns the value of attribute max_players.
3 4 5 |
# File 'lib/bgg/game.rb', line 3 def max_players @max_players end |
#mechanics ⇒ Object (readonly)
Returns the value of attribute mechanics.
3 4 5 |
# File 'lib/bgg/game.rb', line 3 def mechanics @mechanics end |
#min_players ⇒ Object (readonly)
Returns the value of attribute min_players.
3 4 5 |
# File 'lib/bgg/game.rb', line 3 def min_players @min_players end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/bgg/game.rb', line 3 def name @name end |
#names ⇒ Object (readonly)
Returns the value of attribute names.
3 4 5 |
# File 'lib/bgg/game.rb', line 3 def names @names end |
#playing_time ⇒ Object (readonly)
Returns the value of attribute playing_time.
3 4 5 |
# File 'lib/bgg/game.rb', line 3 def @playing_time end |
#publishers ⇒ Object (readonly)
Returns the value of attribute publishers.
3 4 5 |
# File 'lib/bgg/game.rb', line 3 def publishers @publishers end |
#recommended_minimum_age ⇒ Object (readonly)
Returns the value of attribute recommended_minimum_age.
3 4 5 |
# File 'lib/bgg/game.rb', line 3 def recommended_minimum_age @recommended_minimum_age end |
#thumbnail ⇒ Object (readonly)
Returns the value of attribute thumbnail.
3 4 5 |
# File 'lib/bgg/game.rb', line 3 def thumbnail @thumbnail end |
#year_published ⇒ Object (readonly)
Returns the value of attribute year_published.
3 4 5 |
# File 'lib/bgg/game.rb', line 3 def year_published @year_published end |
Class Method Details
.find_by_id(game_id) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# 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 |