1: <?php
2: /*
3: * Copyright (c) 2016 Geraldo B. Landre
4: *
5: * See the file LICENSE for copying permission.
6: */
7: namespace pgn\tags;
8:
9: use utils\Parser;
10:
11: /**
12: * Description of WhiteElo:
13: * 9.1.2: Tags: WhiteElo, BlackElo
14: * These tags use integer values; these are used for FIDE Elo ratings. A value of
15: * "-" is used for an unrated player.
16: * @see pgn_standard.txt
17: * @author Geraldo
18: */
19: class WhiteElo extends Tag {
20:
21: /**
22: * @assert() === "WhiteElo"
23: * @return string
24: */
25: public function getName() {
26: $parsed = Parser::parseClassName(get_class());
27: return $parsed['className'];
28: }
29: /**
30: * @assert () === "-"
31: * @return string
32: */
33: public function getDefaultValue() {
34: return "-";
35: }
36:
37: /**
38: * @assert("1900") === true
39: * @assert("19") === true
40: * @assert(1) === true
41: * @assert("3.1") === false
42: * @assert(3.1) === false
43: * @assert("4.1.2") === false
44: * @assert("-") === false
45: * @assert("?") === true
46: * @assert(NULL) === false
47: * @assert("A") === false
48: * @assert("asdf") === false
49: * @assert("*") === false
50: * @assert("????.??.??") === false
51: * @param string $data
52: * @return boolean
53: */
54: public function validate($data) {
55:
56: if(!parent::validate($data)) {
57: return false;
58: }
59:
60: if($data === '?') {
61: return true;
62: }
63:
64: return preg_match_all("/^" . self::validPattern() . "$/", $data) === 1;
65: }
66:
67: /**
68: *
69: * @return string Valid Regular Expression Pattern for PGN Rounds
70: */
71: static public function validPattern() {
72: return "\d+";
73: }
74:
75: }
76: