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) ⇒ BGGItem
constructor
A new instance of BGGItem.
Constructor Details
#initialize(xml) ⇒ 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 |
# File 'lib/bgg_item.rb', line 7 def initialize(xml) if !xml.nil? @id = get_integer(xml, "item", "id") @type = get_string(xml, "item", "type") @image = get_string(xml, "image") @thumbnail = get_string(xml, "thumbnail") @name = get_string(xml, "name[type='primary']", "value") @alternate_names = get_strings(xml, "name[type='alternate']", "value") @description = get_string(xml, "description") @year_published = get_integer(xml, "yearpublished", "value") @min_players = get_integer(xml, "minplayers", "value") @max_players = get_integer(xml, "maxplayers", "value") @playing_time = get_integer(xml, "playingtime", "value") @min_playing_time = get_integer(xml, "minplaytime", "value") @max_playing_time = get_integer(xml, "maxplaytime", "value") @statistics = nil if !xml.at_css("statistics").nil? @statistics = {} @statistics[:user_ratings] = get_integer(xml, "usersrated", "value") @statistics[:average] = get_float(xml, "average", "value") @statistics[:bayes] = get_float(xml, "bayesaverage", "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", "value") @statistics[:median] = get_float(xml, "median", "value") @statistics[:owned] = get_integer(xml, "owned", "value") @statistics[:trading] = get_integer(xml, "trading", "value") @statistics[:wanting] = get_integer(xml, "wanting", "value") @statistics[:wishing] = get_integer(xml, "wishing", "value") @statistics[:num_comments] = get_integer(xml, "numcomments", "value") @statistics[:num_weights] = get_integer(xml, "numweights", "value") @statistics[:average_weight] = get_integer(xml, "averageweight", "value") end else @id = 0 @type = "" @image = "" @thumbnail = "" @name = "Data pending..." @alternate_names = [] @description = "" @year_published = -1 @min_players = -1 @max_players = -1 @playing_time = -1 @min_playing_time = -1 @max_playing_time = -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 @max_playing_time 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 @min_playing_time 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 @playing_time 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
66 67 68 |
# File 'lib/bgg_item.rb', line 66 def get_user_collection_data(username) return BoardGameGem.get_collection(username, id: @id) end |