BoardGameGem 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/bgg_base.rb +18 -26
- data/lib/bgg_collection.rb +2 -3
- data/lib/bgg_collection_item.rb +15 -16
- data/lib/bgg_family.rb +6 -7
- data/lib/bgg_item.rb +26 -27
- data/lib/bgg_search_result.rb +2 -3
- data/lib/bgg_user.rb +7 -8
- data/lib/boardgamegem/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3eb488f2147d01f50bf5e289daaed8ed6a18f666
|
4
|
+
data.tar.gz: 97a5509a6aa1925f6331b74c55a86625b973052f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f6e04d0e68ec8d73eccef07dd189171bd893cb4dbac86ab605bf59ae2655154157451af204104744cb1a2e274df0baeb0f0d2f092ec9ca6f0b720e96cb608f5
|
7
|
+
data.tar.gz: 4de4f0e259a083c987b0f1cddba03aad5c01fae9f96fefd4d7308feca33cf3d5e9f013fa71f9dd78ca43af80fb3fb9e23f8e91138a1781e896976d1936e66b78
|
data/lib/bgg_base.rb
CHANGED
@@ -1,17 +1,9 @@
|
|
1
1
|
module BoardGameGem
|
2
2
|
class BGGBase
|
3
|
-
def initialize(xml)
|
4
|
-
@xml = xml
|
5
|
-
end
|
6
|
-
|
7
|
-
def to_s
|
8
|
-
return instance_variables.map{|ivar| "#{ivar} => #{instance_variable_get ivar}" }
|
9
|
-
end
|
10
|
-
|
11
3
|
protected
|
12
4
|
|
13
|
-
def get_value(path, key = nil)
|
14
|
-
item =
|
5
|
+
def get_value(xml, path, key = nil)
|
6
|
+
item = xml.at_css(path)
|
15
7
|
if item.nil?
|
16
8
|
return nil
|
17
9
|
end
|
@@ -22,9 +14,9 @@ module BoardGameGem
|
|
22
14
|
end
|
23
15
|
end
|
24
16
|
|
25
|
-
def get_values(path, key = nil)
|
17
|
+
def get_values(xml, path, key = nil)
|
26
18
|
results = []
|
27
|
-
|
19
|
+
xml.css(path).each do |item|
|
28
20
|
if key.nil?
|
29
21
|
results.push(item.content)
|
30
22
|
else
|
@@ -34,32 +26,32 @@ module BoardGameGem
|
|
34
26
|
return results
|
35
27
|
end
|
36
28
|
|
37
|
-
def get_boolean(path, key = nil)
|
38
|
-
return get_integer(path, key) == 1 rescue nil
|
29
|
+
def get_boolean(xml, path, key = nil)
|
30
|
+
return get_integer(xml, path, key) == 1 rescue nil
|
39
31
|
end
|
40
32
|
|
41
|
-
def get_integer(path, key = nil)
|
42
|
-
return get_value(path, key).to_i rescue nil
|
33
|
+
def get_integer(xml, path, key = nil)
|
34
|
+
return get_value(xml, path, key).to_i rescue nil
|
43
35
|
end
|
44
36
|
|
45
|
-
def get_integers(path, key = nil)
|
46
|
-
return get_values(path, key).map {|x| x.to_i } rescue nil
|
37
|
+
def get_integers(xml, path, key = nil)
|
38
|
+
return get_values(xml, path, key).map {|x| x.to_i } rescue nil
|
47
39
|
end
|
48
40
|
|
49
|
-
def get_string(path, key = nil)
|
50
|
-
return get_value(path, key).to_s rescue nil
|
41
|
+
def get_string(xml, path, key = nil)
|
42
|
+
return get_value(xml, path, key).to_s rescue nil
|
51
43
|
end
|
52
44
|
|
53
|
-
def get_strings(path, key = nil)
|
54
|
-
return get_values(path, key).map {|x| x.to_s } rescue nil
|
45
|
+
def get_strings(xml, path, key = nil)
|
46
|
+
return get_values(xml, path, key).map {|x| x.to_s } rescue nil
|
55
47
|
end
|
56
48
|
|
57
|
-
def get_float(path, key = nil)
|
58
|
-
return get_value(path, key).to_f rescue nil
|
49
|
+
def get_float(xml, path, key = nil)
|
50
|
+
return get_value(xml, path, key).to_f rescue nil
|
59
51
|
end
|
60
52
|
|
61
|
-
def get_datetime(path, key)
|
62
|
-
return DateTime.strptime(get_string(path, key), '%F %T')
|
53
|
+
def get_datetime(xml, path, key)
|
54
|
+
return DateTime.strptime(get_string(xml, path, key), '%F %T')
|
63
55
|
end
|
64
56
|
end
|
65
57
|
end
|
data/lib/bgg_collection.rb
CHANGED
@@ -4,10 +4,9 @@ module BoardGameGem
|
|
4
4
|
attr_reader :count, :items
|
5
5
|
|
6
6
|
def initialize(xml)
|
7
|
-
|
8
|
-
@count = get_integer("items", "totalitems")
|
7
|
+
@count = get_integer(xml, "items", "totalitems")
|
9
8
|
@items = []
|
10
|
-
|
9
|
+
xml.css("item").each do |item|
|
11
10
|
@items.push(BGGCollectionItem.new(item))
|
12
11
|
end
|
13
12
|
end
|
data/lib/bgg_collection_item.rb
CHANGED
@@ -4,26 +4,25 @@ module BoardGameGem
|
|
4
4
|
attr_reader :id, :type, :name, :year_published, :image, :thumbnail, :num_players, :status, :num_plays
|
5
5
|
|
6
6
|
def initialize(xml)
|
7
|
-
super
|
8
7
|
@id = xml["objectid"].to_i
|
9
8
|
@type = xml["subtype"]
|
10
|
-
@name = get_string("name")
|
11
|
-
@year_published = get_string("yearpublished")
|
12
|
-
@image = get_string("image")
|
13
|
-
@thumbnail = get_string("thumbnail")
|
14
|
-
@num_players = get_string("numplayers")
|
9
|
+
@name = get_string(xml, "name")
|
10
|
+
@year_published = get_string(xml, "yearpublished")
|
11
|
+
@image = get_string(xml, "image")
|
12
|
+
@thumbnail = get_string(xml, "thumbnail")
|
13
|
+
@num_players = get_string(xml, "numplayers")
|
15
14
|
@status = {
|
16
|
-
:own => get_boolean("status", "own"),
|
17
|
-
:prev_owned => get_boolean("status", "prevowned"),
|
18
|
-
:for_trade => get_boolean("status", "fortrade"),
|
19
|
-
:want => get_boolean("status", "want"),
|
20
|
-
:want_to_play => get_boolean("status", "wanttoplay"),
|
21
|
-
:want_to_buy => get_boolean("status", "wanttobuy"),
|
22
|
-
:wishlist => get_boolean("status", "wishlist"),
|
23
|
-
:preordered => get_boolean("status", "preordered"),
|
24
|
-
:last_modified => get_datetime("status", "lastmodified")
|
15
|
+
:own => get_boolean(xml, "status", "own"),
|
16
|
+
:prev_owned => get_boolean(xml, "status", "prevowned"),
|
17
|
+
:for_trade => get_boolean(xml, "status", "fortrade"),
|
18
|
+
:want => get_boolean(xml, "status", "want"),
|
19
|
+
:want_to_play => get_boolean(xml, "status", "wanttoplay"),
|
20
|
+
:want_to_buy => get_boolean(xml, "status", "wanttobuy"),
|
21
|
+
:wishlist => get_boolean(xml, "status", "wishlist"),
|
22
|
+
:preordered => get_boolean(xml, "status", "preordered"),
|
23
|
+
:last_modified => get_datetime(xml, "status", "lastmodified")
|
25
24
|
}
|
26
|
-
@num_plays = get_integer("numplays")
|
25
|
+
@num_plays = get_integer(xml, "numplays")
|
27
26
|
end
|
28
27
|
|
29
28
|
def to_item(statistics = false)
|
data/lib/bgg_family.rb
CHANGED
@@ -4,13 +4,12 @@ module BoardGameGem
|
|
4
4
|
attr_reader :id, :thumbnail, :image, :name, :alternate_names, :description
|
5
5
|
|
6
6
|
def initialize(xml)
|
7
|
-
|
8
|
-
@
|
9
|
-
@
|
10
|
-
@
|
11
|
-
@
|
12
|
-
@
|
13
|
-
@description = get_string("description")
|
7
|
+
@id = get_integer(xml, "item", "id")
|
8
|
+
@thumbnail = get_string(xml, "thumbnail")
|
9
|
+
@image = get_string(xml, "image")
|
10
|
+
@name = get_string(xml, "name[type='primary']", "value")
|
11
|
+
@alternate_names = get_strings(xml, "name[type='alternate']", "value")
|
12
|
+
@description = get_string(xml, "description")
|
14
13
|
end
|
15
14
|
end
|
16
15
|
end
|
data/lib/bgg_item.rb
CHANGED
@@ -5,27 +5,26 @@ module BoardGameGem
|
|
5
5
|
:playing_time, :min_playing_time, :max_playing_time, :statistics
|
6
6
|
|
7
7
|
def initialize(xml)
|
8
|
-
|
9
|
-
@
|
10
|
-
@
|
11
|
-
@
|
12
|
-
@
|
13
|
-
@
|
14
|
-
@
|
15
|
-
@
|
16
|
-
@
|
17
|
-
@
|
18
|
-
@
|
19
|
-
@
|
20
|
-
@max_playing_time = get_integer("maxplaytime", "value")
|
8
|
+
@id = get_integer(xml, "item", "id")
|
9
|
+
@type = get_string(xml, "item", "type")
|
10
|
+
@thumbnail = get_string(xml, "thumbnail")
|
11
|
+
@name = get_string(xml, "name[type='primary']", "value")
|
12
|
+
@alternate_names = get_strings(xml, "name[type='alternate']", "value")
|
13
|
+
@description = get_string(xml, "description")
|
14
|
+
@year_published = get_integer(xml, "yearpublished", "value")
|
15
|
+
@min_players = get_integer(xml, "minplayers", "value")
|
16
|
+
@max_players = get_integer(xml, "maxplayers", "value")
|
17
|
+
@playing_time = get_integer(xml, "playingtime", "value")
|
18
|
+
@min_playing_time = get_integer(xml, "minplaytime", "value")
|
19
|
+
@max_playing_time = get_integer(xml, "maxplaytime", "value")
|
21
20
|
@statistics = nil
|
22
|
-
if
|
21
|
+
if !xml.at_css("statistics").nil?
|
23
22
|
@statistics = {}
|
24
|
-
@statistics[:user_ratings] = get_integer("usersrated", "value")
|
25
|
-
@statistics[:average] = get_float("average", "value")
|
26
|
-
@statistics[:bayes] = get_float("bayesaverage", "value")
|
23
|
+
@statistics[:user_ratings] = get_integer(xml, "usersrated", "value")
|
24
|
+
@statistics[:average] = get_float(xml, "average", "value")
|
25
|
+
@statistics[:bayes] = get_float(xml, "bayesaverage", "value")
|
27
26
|
@statistics[:ranks] = []
|
28
|
-
|
27
|
+
xml.css("rank").each do |rank|
|
29
28
|
rank_data = {}
|
30
29
|
rank_data[:type] = rank["type"]
|
31
30
|
rank_data[:name] = rank["name"]
|
@@ -33,15 +32,15 @@ module BoardGameGem
|
|
33
32
|
rank_data[:bayes] = rank["bayesaverage"].to_f
|
34
33
|
@statistics[:ranks].push(rank_data)
|
35
34
|
end
|
36
|
-
@statistics[:stddev] = get_float("stddev", "value")
|
37
|
-
@statistics[:median] = get_float("median", "value")
|
38
|
-
@statistics[:owned] = get_integer("owned", "value")
|
39
|
-
@statistics[:trading] = get_integer("trading", "value")
|
40
|
-
@statistics[:wanting] = get_integer("wanting", "value")
|
41
|
-
@statistics[:wishing] = get_integer("wishing", "value")
|
42
|
-
@statistics[:num_comments] = get_integer("numcomments", "value")
|
43
|
-
@statistics[:num_weights] = get_integer("numweights", "value")
|
44
|
-
@statistics[:average_weight] = get_integer("averageweight", "value")
|
35
|
+
@statistics[:stddev] = get_float(xml, "stddev", "value")
|
36
|
+
@statistics[:median] = get_float(xml, "median", "value")
|
37
|
+
@statistics[:owned] = get_integer(xml, "owned", "value")
|
38
|
+
@statistics[:trading] = get_integer(xml, "trading", "value")
|
39
|
+
@statistics[:wanting] = get_integer(xml, "wanting", "value")
|
40
|
+
@statistics[:wishing] = get_integer(xml, "wishing", "value")
|
41
|
+
@statistics[:num_comments] = get_integer(xml, "numcomments", "value")
|
42
|
+
@statistics[:num_weights] = get_integer(xml, "numweights", "value")
|
43
|
+
@statistics[:average_weight] = get_integer(xml, "averageweight", "value")
|
45
44
|
end
|
46
45
|
|
47
46
|
end
|
data/lib/bgg_search_result.rb
CHANGED
@@ -4,11 +4,10 @@ module BoardGameGem
|
|
4
4
|
attr_reader :id, :type, :name, :year_published
|
5
5
|
|
6
6
|
def initialize(xml)
|
7
|
-
super
|
8
7
|
@id = xml["id"].to_i
|
9
8
|
@type = xml["type"]
|
10
|
-
@name = get_string("name", "value")
|
11
|
-
@year_published = get_string("yearpublished", "value")
|
9
|
+
@name = get_string(xml, "name", "value")
|
10
|
+
@year_published = get_string(xml, "yearpublished", "value")
|
12
11
|
end
|
13
12
|
|
14
13
|
def to_item(statistics = false)
|
data/lib/bgg_user.rb
CHANGED
@@ -4,14 +4,13 @@ module BoardGameGem
|
|
4
4
|
attr_reader :id, :name, :avatar, :year_registered, :last_login, :state, :trade_rating
|
5
5
|
|
6
6
|
def initialize(xml)
|
7
|
-
|
8
|
-
@
|
9
|
-
@
|
10
|
-
@
|
11
|
-
@
|
12
|
-
@
|
13
|
-
@
|
14
|
-
@trade_rating = get_integer("traderating", "value")
|
7
|
+
@id = get_integer(xml, "user", "id")
|
8
|
+
@name = get_string(xml, "user", "name")
|
9
|
+
@avatar = get_string(xml, "avatarlink", "value")
|
10
|
+
@year_registered = get_integer(xml, "yearregistered", "value")
|
11
|
+
@last_login = get_string(xml, "lastlogin", "value")
|
12
|
+
@state = get_string(xml, "stateorprovince", "value")
|
13
|
+
@trade_rating = get_integer(xml, "traderating", "value")
|
15
14
|
end
|
16
15
|
|
17
16
|
def get_collection
|
data/lib/boardgamegem/version.rb
CHANGED