Skip to content

CardSet

Represents a Flesh and Blood card set. Each card set has the following fields:

Attributes:

Name Type Description
editions list[str]

The list of editions the set was printed for.

identifier str

The string shorthand identifier of the set.

name str

The full name of the set.

release_date Optional[datetime.date]

The release date of the card set (if applicable).

Source code in fab/card_set.py
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
@dataclasses.dataclass
class CardSet:
    '''
    Represents a Flesh and Blood card set. Each card set has the following
    fields:

    Attributes:
      editions: The list of editions the set was printed for.
      identifier: The string shorthand identifier of the set.
      name: The full name of the set.
      release_date: The release date of the card set (if applicable).
    '''

    editions: list[str]
    identifier: str
    name: str
    release_date: Optional[datetime.date]

    def __getitem__(self, key: str) -> Any:
        '''
        Allows one to access fields of a card set via dictionary syntax.

        Args:
          key: The `str` corresponding to the name of the `CardSet` field to access.

        Returns:
          The value of the associated `CardSet` field.
        '''
        return self.__dict__[key]

    def __hash__(self) -> Any:
        '''
        Returns the hash representation of the card set.

        Returns:
          The hash representation of the card set.
        '''
        return hash((self.identifier, self.name))

    def __str__(self) -> str:
        '''
        Returns the string representation of the card set.

        This is an alias of the `CardSet.to_json()` method.

        Returns:
          The JSON string representation of the card set.
        '''
        return self.to_json()

    def keys(self) -> list[str]:
        '''
        Returns the dictionary keys associated with this card set class.

        Returns:
          A `list` of dictionary keys associated with the fields of the set.
        '''
        return list(self.__dict__.keys())

    @staticmethod
    def from_datestr_dict(jsondict: dict[str, Any]) -> CardSet:
        '''
        Creates a new card set from a dictionary object containing unparsed
        date strings.

        Args:
          jsondict: A raw `dict` object representing a card set.

        Returns:
          A new `CardSet` object.
        '''
        rep = copy.deepcopy(jsondict)
        if not rep['release_date'] is None:
            rep['release_date'] = datetime.datetime.strptime(rep['release_date'], DATE_FORMAT).date()
        return CardSet(**rep)

    @staticmethod
    def from_json(jsonstr: str) -> CardSet:
        '''
        Creates a new card set from the specified JSON string.

        Args:
          jsonstr: The JSON string representation to parse.

        Returns:
          A new `CardSet` object from the parsed data.
        '''
        return CardSet.from_datestr_dict(json.loads(jsonstr))

    def to_datestr_dict(self) -> dict:
        '''
        Converts the card set into a dictionary where the `release_date` field
        is set to its string representation.

        Returns:
          A raw `dict` representing the card set.
        '''
        rep = copy.deepcopy(self.__dict__)
        if not rep['release_date'] is None:
            rep['release_date'] = rep['release_date'].strftime(DATE_FORMAT)
        return rep

    def to_json(self) -> str:
        '''
        Converts this card set into a JSON string representation.

        Returns:
          The JSON string representation of the set.
        '''
        return json.dumps(self.to_datestr_dict(), indent=JSON_INDENT)

__getitem__(key)

Allows one to access fields of a card set via dictionary syntax.

Parameters:

Name Type Description Default
key str

The str corresponding to the name of the CardSet field to access.

required

Returns:

Type Description
Any

The value of the associated CardSet field.

Source code in fab/card_set.py
45
46
47
48
49
50
51
52
53
54
55
def __getitem__(self, key: str) -> Any:
    '''
    Allows one to access fields of a card set via dictionary syntax.

    Args:
      key: The `str` corresponding to the name of the `CardSet` field to access.

    Returns:
      The value of the associated `CardSet` field.
    '''
    return self.__dict__[key]

__hash__()

Returns the hash representation of the card set.

Returns:

Type Description
Any

The hash representation of the card set.

Source code in fab/card_set.py
57
58
59
60
61
62
63
64
def __hash__(self) -> Any:
    '''
    Returns the hash representation of the card set.

    Returns:
      The hash representation of the card set.
    '''
    return hash((self.identifier, self.name))

__str__()

Returns the string representation of the card set.

This is an alias of the CardSet.to_json() method.

Returns:

Type Description
str

The JSON string representation of the card set.

Source code in fab/card_set.py
66
67
68
69
70
71
72
73
74
75
def __str__(self) -> str:
    '''
    Returns the string representation of the card set.

    This is an alias of the `CardSet.to_json()` method.

    Returns:
      The JSON string representation of the card set.
    '''
    return self.to_json()

from_datestr_dict(jsondict) staticmethod

Creates a new card set from a dictionary object containing unparsed date strings.

Parameters:

Name Type Description Default
jsondict dict[str, Any]

A raw dict object representing a card set.

required

Returns:

Type Description
CardSet

A new CardSet object.

Source code in fab/card_set.py
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
@staticmethod
def from_datestr_dict(jsondict: dict[str, Any]) -> CardSet:
    '''
    Creates a new card set from a dictionary object containing unparsed
    date strings.

    Args:
      jsondict: A raw `dict` object representing a card set.

    Returns:
      A new `CardSet` object.
    '''
    rep = copy.deepcopy(jsondict)
    if not rep['release_date'] is None:
        rep['release_date'] = datetime.datetime.strptime(rep['release_date'], DATE_FORMAT).date()
    return CardSet(**rep)

from_json(jsonstr) staticmethod

Creates a new card set from the specified JSON string.

Parameters:

Name Type Description Default
jsonstr str

The JSON string representation to parse.

required

Returns:

Type Description
CardSet

A new CardSet object from the parsed data.

Source code in fab/card_set.py
103
104
105
106
107
108
109
110
111
112
113
114
@staticmethod
def from_json(jsonstr: str) -> CardSet:
    '''
    Creates a new card set from the specified JSON string.

    Args:
      jsonstr: The JSON string representation to parse.

    Returns:
      A new `CardSet` object from the parsed data.
    '''
    return CardSet.from_datestr_dict(json.loads(jsonstr))

keys()

Returns the dictionary keys associated with this card set class.

Returns:

Type Description
list[str]

A list of dictionary keys associated with the fields of the set.

Source code in fab/card_set.py
77
78
79
80
81
82
83
84
def keys(self) -> list[str]:
    '''
    Returns the dictionary keys associated with this card set class.

    Returns:
      A `list` of dictionary keys associated with the fields of the set.
    '''
    return list(self.__dict__.keys())

to_datestr_dict()

Converts the card set into a dictionary where the release_date field is set to its string representation.

Returns:

Type Description
dict

A raw dict representing the card set.

Source code in fab/card_set.py
116
117
118
119
120
121
122
123
124
125
126
127
def to_datestr_dict(self) -> dict:
    '''
    Converts the card set into a dictionary where the `release_date` field
    is set to its string representation.

    Returns:
      A raw `dict` representing the card set.
    '''
    rep = copy.deepcopy(self.__dict__)
    if not rep['release_date'] is None:
        rep['release_date'] = rep['release_date'].strftime(DATE_FORMAT)
    return rep

to_json()

Converts this card set into a JSON string representation.

Returns:

Type Description
str

The JSON string representation of the set.

Source code in fab/card_set.py
129
130
131
132
133
134
135
136
def to_json(self) -> str:
    '''
    Converts this card set into a JSON string representation.

    Returns:
      The JSON string representation of the set.
    '''
    return json.dumps(self.to_datestr_dict(), indent=JSON_INDENT)