bgg-parser 0.0.4 → 0.0.5
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-parser.rb +23 -21
- 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: c0e42e7a1ed0a1e3e0f47be8629a98f99c351d0c
|
4
|
+
data.tar.gz: 6651ab08e5899f541d1a490a2a0ac7bb7ba86fc4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dded6e31052e3f0c074dba943158a63224320703737d9f913d010a3645991a77255befdf9e274c31d73d52270fc594780f86a79efbc080be4ba8b72efd47c5de
|
7
|
+
data.tar.gz: 338b3ffb27d60714f5b07301b40b1505b68bf614e28d7175d251ab44462492229f971e0704efb16043f6d028fe84f2fb8f8ac053607f09d8adf250205fa8cb53
|
data/lib/bgg-parser.rb
CHANGED
@@ -1,29 +1,31 @@
|
|
1
1
|
class BggParser
|
2
2
|
def self.games_parse(raw_json, library_id)
|
3
3
|
raw_json["item"].each do |game_json|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
4
|
+
if game_json["type"] == "boardgame"
|
5
|
+
game = Game.find_or_initialize_by(bgg_id: game_json["id"])
|
6
|
+
game.name = game_json["name"][0]["value"] if game_json["name"]
|
7
|
+
game.description = ActionView::Base.full_sanitizer.sanitize(game_json["description"][0]).gsub(/\n/, "").gsub(/\s+/, " ")
|
8
|
+
game.minplayers = game_json["minplayers"][0]["value"].to_i if game_json["minplayers"]
|
9
|
+
game.maxplayers = game_json["maxplayers"][0]["value"].to_i if game_json["maxplayers"]
|
10
|
+
game.minplaytime = game_json["minplaytime"][0]["value"].to_i if game_json["minplaytime"]
|
11
|
+
game.maxplaytime = game_json["maxplaytime"][0]["value"].to_i if game_json["maxplaytime"]
|
12
|
+
game.poll = game_json["poll"][0] if game_json["poll"] && game_json["poll"][0]["name"] == "suggested_numplayers"
|
13
|
+
game.image_url = game_json["image"][0] if game_json["image"]
|
14
|
+
game.thumbnail_url = game_json["thumbnail"][0] if game_json["thumbnail"]
|
14
15
|
|
15
|
-
|
16
|
+
if game.save
|
16
17
|
|
17
|
-
|
18
|
+
GamesLibrary.create game: game, library_id: library_id
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
20
|
+
if game_json["link"]
|
21
|
+
game_json["link"].each do |row|
|
22
|
+
if row["type"] == "boardgamecategory"
|
23
|
+
category = Category.find_or_create_by bgg_id: row["id"], name: row["value"]
|
24
|
+
gamescategory = GamesCategory.create(game: game, category: category) if category.valid?
|
25
|
+
elsif row["type"] == "boardgamemechanic"
|
26
|
+
mechanic = Mechanic.find_or_create_by bgg_id: row["id"], name: row["value"]
|
27
|
+
gamesmechanic = GamesMechanic.create(game: game, mechanic: mechanic) if mechanic.valid?
|
28
|
+
end
|
27
29
|
end
|
28
30
|
end
|
29
31
|
end
|
@@ -32,6 +34,6 @@ class BggParser
|
|
32
34
|
end
|
33
35
|
|
34
36
|
def self.user_parse(raw_json, user_id)
|
35
|
-
|
37
|
+
|
36
38
|
end
|
37
39
|
end
|