[LIB-13] Method scanUrl implementation for several scanners
[chesshog-scanner.git] / src / main / java / org / hedgecode / chess / scanner / json / format / JSONTournamentFormat.java
1 /*
2  * Copyright (c) 2019-2020. Developed by Hedgecode.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *   http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.hedgecode.chess.scanner.json.format;
18
19 import java.util.ArrayList;
20 import java.util.List;
21
22 import com.google.gson.annotations.SerializedName;
23
24 import org.hedgecode.chess.scanner.format.Game;
25 import org.hedgecode.chess.scanner.format.RoomData;
26 import org.hedgecode.chess.scanner.format.TournamentFormat;
27
28 /**
29  * JSONTournamentFormat
30  *
31  * @author Dmitry Samoshin aka gotty
32  */
33 public class JSONTournamentFormat extends AbstractBaseFormat implements TournamentFormat {
34
35     private static final String GAME_URL_FORMAT = "%s-%s";
36
37     @SerializedName("roomData")
38     private JSONRoomData roomData;
39
40     JSONTournamentFormat() {
41     }
42
43     @Override
44     public String id() {
45         return Integer.toString(
46                 roomData().room().id()
47         );
48     }
49
50     @Override
51     public String name() {
52         return roomData().room().name();
53     }
54
55     @Override
56     public RoomData roomData() {
57         return roomData;
58     }
59
60     @Override
61     public List<String> gameUrls() {
62         List<String> gameUrls = new ArrayList<>();
63         for (Game game : roomData.games()) {
64             gameUrls.add(
65                     String.format(GAME_URL_FORMAT, game.roundSlug(), game.slug())
66             );
67         }
68         return gameUrls;
69     }
70
71 }