Class: BoardGameGem::BGGItem

Inherits:
BGGBase
  • Object
show all
Defined in:
lib/bgg_item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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)
    @playing_time = get_integer(xml, "playingtime", api_key_value)
    @min_playing_time = get_integer(xml, "minplaytime", api_key_value)
    @max_playing_time = 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
    @playing_time = -1
    @min_playing_time = -1
    @max_playing_time = -1
    @statistics = nil
  end
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



4
5
6
# File 'lib/bgg_item.rb', line 4

def description
  @description
end

#idObject (readonly)

Returns the value of attribute id.



4
5
6
# File 'lib/bgg_item.rb', line 4

def id
  @id
end

#imageObject (readonly)

Returns the value of attribute image.



4
5
6
# File 'lib/bgg_item.rb', line 4

def image
  @image
end

#max_playersObject (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_timeObject (readonly)

Returns the value of attribute max_playing_time.



4
5
6
# File 'lib/bgg_item.rb', line 4

def max_playing_time
  @max_playing_time
end

#min_playersObject (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_timeObject (readonly)

Returns the value of attribute min_playing_time.



4
5
6
# File 'lib/bgg_item.rb', line 4

def min_playing_time
  @min_playing_time
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/bgg_item.rb', line 4

def name
  @name
end

#playing_timeObject (readonly)

Returns the value of attribute playing_time.



4
5
6
# File 'lib/bgg_item.rb', line 4

def playing_time
  @playing_time
end

#statisticsObject (readonly)

Returns the value of attribute statistics.



4
5
6
# File 'lib/bgg_item.rb', line 4

def statistics
  @statistics
end

#thumbnailObject (readonly)

Returns the value of attribute thumbnail.



4
5
6
# File 'lib/bgg_item.rb', line 4

def thumbnail
  @thumbnail
end

#typeObject (readonly)

Returns the value of attribute type.



4
5
6
# File 'lib/bgg_item.rb', line 4

def type
  @type
end

#year_publishedObject (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