Class: BoardGameGem::BGGItem
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#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.
-
#max_playing_time ⇒ Object
readonly
Returns the value of attribute max_playing_time.
-
#min_players ⇒ Object
readonly
Returns the value of attribute min_players.
-
#min_playing_time ⇒ Object
readonly
Returns the value of attribute min_playing_time.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#playing_time ⇒ Object
readonly
Returns the value of attribute playing_time.
-
#statistics ⇒ Object
readonly
Returns the value of attribute statistics.
-
#thumbnail ⇒ Object
readonly
Returns the value of attribute thumbnail.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#year_published ⇒ Object
readonly
Returns the value of attribute year_published.
Instance Method Summary collapse
- #get_user_collection_data(username) ⇒ Object
-
#initialize(xml, api = 2) ⇒ BGGItem
constructor
A new instance of BGGItem.
Constructor Details
#initialize(xml, api = 2) ⇒ BGGItem
Returns a new instance of BGGItem.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 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 |
# File 'lib/bgg_item.rb', line 7 def initialize(xml, api = 2) @api = api if !xml.nil? @id = get_integer(xml, key_for_api("boardgame", "item"), key_for_api("objectid", "id")) if api == 2 @type = get_string(xml, "item", "type") else if !get_value(xml, "boardgame", "subtypemismatch").nil? if !get_value(xml, "videogameplatform").nil? @type = "videogame" elsif !get_value(xml, "boardgameexpansion").nil? @type = "boardgameexpansion" elsif !get_value(xml, "rpgpublisher").nil? @type = "rpgitem" end else @type = "boardgame" end end @image = get_string(xml, "image") @thumbnail = get_string(xml, "thumbnail") @name = get_string(xml, key_for_api("name", "name[type='primary']"), api_key_value) @alternate_names = get_strings(xml, "name[type='alternate']", "value") @description = get_string(xml, "description") @year_published = get_integer(xml, "yearpublished", api_key_value) @min_players = get_integer(xml, "minplayers", api_key_value) @max_players = get_integer(xml, "maxplayers", api_key_value) = get_integer(xml, "playingtime", api_key_value) = get_integer(xml, "minplaytime", api_key_value) = get_integer(xml, "maxplaytime", api_key_value) @statistics = nil if !xml.at_css("statistics").nil? @statistics = {} @statistics[:user_ratings] = get_integer(xml, "usersrated", api_key_value) @statistics[:average] = get_float(xml, "average", api_key_value) @statistics[:bayes] = get_float(xml, "bayesaverage", api_key_value) @statistics[:ranks] = [] xml.css("rank").each do |rank| rank_data = {} rank_data[:type] = rank["type"] rank_data[:name] = rank["name"] rank_data[:friendly_name] = rank["friendlyname"] rank_data[:value] = rank["value"].to_i rank_data[:bayes] = rank["bayesaverage"].to_f @statistics[:ranks].push(rank_data) end @statistics[:stddev] = get_float(xml, "stddev", api_key_value) @statistics[:median] = get_float(xml, "median", api_key_value) @statistics[:owned] = get_integer(xml, "owned", api_key_value) @statistics[:trading] = get_integer(xml, "trading", api_key_value) @statistics[:wanting] = get_integer(xml, "wanting", api_key_value) @statistics[:wishing] = get_integer(xml, "wishing", api_key_value) @statistics[:num_comments] = get_integer(xml, "numcomments", api_key_value) @statistics[:num_weights] = get_integer(xml, "numweights", api_key_value) @statistics[:average_weight] = get_integer(xml, "averageweight", api_key_value) end else @id = 0 @type = "" @image = "" @thumbnail = "" @name = "Data pending..." @alternate_names = [] @description = "" @year_published = -1 @min_players = -1 @max_players = -1 = -1 = -1 = -1 @statistics = nil end end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
4 5 6 |
# File 'lib/bgg_item.rb', line 4 def description @description end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
4 5 6 |
# File 'lib/bgg_item.rb', line 4 def id @id end |
#image ⇒ Object (readonly)
Returns the value of attribute image.
4 5 6 |
# File 'lib/bgg_item.rb', line 4 def image @image end |
#max_players ⇒ Object (readonly)
Returns the value of attribute max_players.
4 5 6 |
# File 'lib/bgg_item.rb', line 4 def max_players @max_players end |
#max_playing_time ⇒ Object (readonly)
Returns the value of attribute max_playing_time.
4 5 6 |
# File 'lib/bgg_item.rb', line 4 def end |
#min_players ⇒ Object (readonly)
Returns the value of attribute min_players.
4 5 6 |
# File 'lib/bgg_item.rb', line 4 def min_players @min_players end |
#min_playing_time ⇒ Object (readonly)
Returns the value of attribute min_playing_time.
4 5 6 |
# File 'lib/bgg_item.rb', line 4 def end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/bgg_item.rb', line 4 def name @name end |
#playing_time ⇒ Object (readonly)
Returns the value of attribute playing_time.
4 5 6 |
# File 'lib/bgg_item.rb', line 4 def end |
#statistics ⇒ Object (readonly)
Returns the value of attribute statistics.
4 5 6 |
# File 'lib/bgg_item.rb', line 4 def statistics @statistics end |
#thumbnail ⇒ Object (readonly)
Returns the value of attribute thumbnail.
4 5 6 |
# File 'lib/bgg_item.rb', line 4 def thumbnail @thumbnail end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/bgg_item.rb', line 4 def type @type end |
#year_published ⇒ Object (readonly)
Returns the value of attribute year_published.
4 5 6 |
# File 'lib/bgg_item.rb', line 4 def year_published @year_published end |
Instance Method Details
#get_user_collection_data(username) ⇒ Object
81 82 83 |
# File 'lib/bgg_item.rb', line 81 def get_user_collection_data(username) return BoardGameGem.get_collection(username, id: @id) end |