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) ⇒ 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

#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



66
67
68
# File 'lib/bgg_item.rb', line 66

def get_user_collection_data(username)
	return BoardGameGem.get_collection(username, id: @id)
end