bgg-parser 0.0.2 → 0.0.3
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 +16 -12
- 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: 36435910e624dfb3496ef1b67294d5e62a45a508
|
4
|
+
data.tar.gz: 1c76d30dfbd78e0b45e4e24817c2ade0d9375ee6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c161b244c0e629b8f7e81fbb6836667a2d4040fe4789851bcd85f8688abb30c95d970e4bb5986ca2e3d1b07003836795b6b50151ac46b1f100c7730f0a6079f
|
7
|
+
data.tar.gz: b76c7e1c7e991833d7696d01845ab8061d0435c695aeb9a5fc31ebbf847ea1c47de679d51b7be71f68290ffbe1f6867307fe7c24c9d6a0f7fecbcb6982ca1e97
|
data/lib/bgg-parser.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
class BggParser
|
2
|
-
def self.
|
2
|
+
def self.games_parse(raw_json, library_id)
|
3
3
|
raw_json["item"].each do |game_json|
|
4
|
-
game = Game.
|
5
|
-
game.bgg_id = game_json["id"]
|
4
|
+
game = Game.find_or_initialize_by(bgg_id: game_json["id"])
|
6
5
|
game.name = game_json["name"][0]["value"]
|
7
6
|
game.description = game_json["description"]
|
8
7
|
game.minplayers = game_json["minplayers"][0]["value"].to_i
|
@@ -13,19 +12,24 @@ class BggParser
|
|
13
12
|
game.image_url = game_json["image"][0]
|
14
13
|
game.thumbnail_url = game_json["thumbnail"][0]
|
15
14
|
|
16
|
-
game.save
|
15
|
+
if game.save
|
17
16
|
|
18
|
-
|
17
|
+
GamesLibrary.create game: game, library_id: library_id
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
19
|
+
game_json["link"].each do |row|
|
20
|
+
if row["type"] == "boardgamecategory"
|
21
|
+
category = Category.find_or_create_by bgg_id: row["id"], name: row["value"]
|
22
|
+
gamescategory = GamesCategory.create(game: game, category: category) if category.valid?
|
23
|
+
elsif row["type"] == "boardgamemechanic"
|
24
|
+
mechanic = Mechanic.find_or_create_by bgg_id: row["id"], name: row["value"]
|
25
|
+
gamesmechanic = GamesMechanic.create(game: game, mechanic: mechanic) if mechanic.valid?
|
26
|
+
end
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
31
|
+
|
32
|
+
def self.user_parse(raw_json, user_id)
|
33
|
+
|
34
|
+
end
|
31
35
|
end
|