Skip to content

Card

Represents a Flesh and Blood card.

Note

fab treats all prints and versions of a card as under the same Card object. If any change is made to the card's body text or attributes between prints, it can be assumed that fab lists the latest print of the card.

Attributes:

Name Type Description
body Optional[str]

The full body text of the card, excluding flavor text.

cost int | str | None

The resource cost of the card.

defense int | str | None

The defense value of the card.

flavor_text Optional[str]

Any lore text printed on the body of the card.

full_name str

The full name of the card, including pitch value.

grants list[str]

A list of keywords this card grants to other cards.

health Optional[int]

The health value of the card.

identifiers list[str]

The list of card identifiers, such as RNR012.

image_urls list[str]

A list of card image URLs.

intelligence Optional[int]

The intelligence value of the card.

keywords list[str]

A list of keywords associated with the card, such as Dominate.

legality dict[str, bool]

Whether this card is currently legal for various formats (see meta.GAME_FORMATS).

name str

The name of the card, excluding pitch value.

pitch Optional[int]

The pitch value of the card.

power int | str | None

The (attack) power of the card.

rarities list[str]

The list of rarities associated with each card identifier.

sets list[str]

The list of card set codes associated with the card.

tags list[str]

A collection of user-defined tags.

type_text str

The full type box text of the card.

types list[str]

The list of types present in the card's type box.

Source code in fab/card.py
 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
@dataclasses.dataclass
class Card:
    '''
    Represents a Flesh and Blood card.

    Note:
      `fab` treats all prints and versions of a card as under the same `Card`
      object. If any change is made to the card's body text or attributes
      between prints, it can be assumed that `fab` lists the latest print of the
      card.

    Attributes:
      body: The full body text of the card, excluding flavor text.
      cost: The resource cost of the card.
      defense: The defense value of the card.
      flavor_text: Any lore text printed on the body of the card.
      full_name: The full name of the card, including pitch value.
      grants: A list of keywords this card grants to other cards.
      health: The health value of the card.
      identifiers: The list of card identifiers, such as `RNR012`.
      image_urls: A list of card image URLs.
      intelligence: The intelligence value of the card.
      keywords: A list of keywords associated with the card, such as `Dominate`.
      legality: Whether this card is _currently_ legal for various formats (see `meta.GAME_FORMATS`).
      name: The name of the card, excluding pitch value.
      pitch: The pitch value of the card.
      power: The (attack) power of the card.
      rarities: The list of rarities associated with each card identifier.
      sets: The list of card set codes associated with the card.
      tags: A collection of user-defined tags.
      type_text: The full type box text of the card.
      types: The list of types present in the card's type box.
    '''

    body: Optional[str]
    cost: int | str | None
    defense: int | str | None
    flavor_text: Optional[str]
    full_name: str
    grants: list[str]
    health: Optional[int]
    identifiers: list[str]
    image_urls: list[str]
    intelligence: Optional[int]
    keywords: list[str]
    legality: dict[str, bool]
    name: str
    pitch: Optional[int]
    power: int | str | None
    rarities: list[str]
    sets: list[str]
    tags: list[str]
    type_text: str
    types: list[str]

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

        Args:
          key: The name of the class attribute to fetch.

        Returns:
          The value associated with the specified field.
        '''
        return self.__dict__[key]

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

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

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

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

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

    @staticmethod
    def from_full_name(full_name: str, catalog: Optional[CardList] = None) -> Card:
        '''
        Creates a new card from its full name.

        Note:
          To instantiate the card this way, a card catalog (`CardList`) must be
          provided, defaulting to `card.CARD_CATALOG`.

        Args:
          full_name: The full name of the card (including pitch value, if applicable).
          catalog: The card catalog to use as a reference, defaulting to `card.CARD_CATALOG` if `None`.

        Returns:
          A new `Card` object.
        '''
        _catalog = CARD_CATALOG if catalog is None else catalog
        if _catalog is None: raise Exception('specified card catalog has not been initialized')
        grouped = _catalog.group(by='full_name')
        if not full_name in grouped:
            raise Exception(f'specified card catalog does not contain a card will full name "{full_name}"')
        return copy.deepcopy(grouped[full_name][0])

    @staticmethod
    def from_identifier(identifier: str, catalog: Optional[CardList] = None) -> Card:
        '''
        Creates a new card from its identifier.

        Note:
          To instantiate the card this way, a card catalog (`CardList`) must be
          provided, defaulting to `card.CARD_CATALOG`.

        Args:
          identifier: The identifier of the card.
          catalog: The card catalog to use as a reference, defaulting to `card.CARD_CATALOG` if `None`.

        Returns:
          A new `Card` object.
        '''
        _catalog = CARD_CATALOG if catalog is None else catalog
        if _catalog is None: raise Exception('specified card catalog has not been initialized')
        for card in _catalog:
            if identifier in card.identifiers:
                return copy.deepcopy(card)
        raise Exception(f'no card in catalog found with identifier "{identifier}"')

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

        Args:
          jsonstr: The JSON string representation to parse.

        Returns:
          A new `Card` object.
        '''
        return Card(**json.loads(jsonstr))

    def image(self, height: int = 314, index: int = -1, width: int = 225) -> Any:
        '''
        Display an image of this card, optionally providing an alternative
        index to use.

        Args:
          height: The height to scale the resulting image to, in pixels.
          index: The target `image_urls` index to fetch image data for.
          width: The width to scale the resulting image to, in pixels.

        Returns:
          The image representation of the card.
        '''
        if not self.image_urls: return 'No images available'
        return display(Image(self.image_urls[index], height=height, width=width))

    def is_action(self) -> bool:
        '''
        Whether this card is an action card.

        Returns:
          Whether the card contains the _Action_ type.
        '''
        return 'Action' in self.types

    def is_attack(self) -> bool:
        '''
        Whether this card is an attack card.

        Returns:
          Whether the card contains the _Attack_ type.
        '''
        return 'Attack' in self.types

    def is_attack_reaction(self) -> bool:
        '''
        Whether this card is an attack reaction card.

        Returns:
          Whether the card contains the _Attack Reaction_ type.
        '''
        return 'Attack Reaction' in self.types

    def is_aura(self) -> bool:
        '''
        Whether this card is an aura card.

        Returns:
          Whether the card contains the _Aura_ type.
        '''
        return 'Aura' in self.types

    def is_blue(self) -> bool:
        '''
        Whether this is a blue card.

        Returns:
          Whether this card pitches for 3 resources.
        '''
        return self.pitch == 3 if isinstance(self.pitch, int) else False

    def is_defense_reaction(self) -> bool:
        '''
        Whether this card is a defense reaction card.

        Returns:
          Whether the card contains the _Defense Reaction_ type.
        '''
        return 'Defense Reaction' in self.types

    def is_equipment(self) -> bool:
        '''
        Whether this card is an equipment card.

        Returns:
          Whether the card contains the _Equipment_ type.
        '''
        return 'Equipment' in self.types

    def is_hero(self) -> bool:
        '''
        Whether this card is a hero card.

        Returns:
          Whether the card contains the _Hero_ type.
        '''
        return 'Hero' in self.types

    def is_instant(self) -> bool:
        '''
        Whether this card is an instant card.

        Returns:
          Whether the card contains the _Instant_ type.
        '''
        return 'Instant' in self.types

    def is_item(self) -> bool:
        '''
        Whether this card is an item card.

        Returns:
          Whether the card contains the _Item_ type.
        '''
        return 'Item' in self.types

    def is_legal(self, format: Optional[str] = None) -> bool:
        '''
        Whether this card is legal for the specified format, or if `format` is
        `None`, returns `False` if this card is banned in _any_ format.

        Args:
          format: The code of the card format to check, or `None` to check all formats.

        Returns:
          Whether the card is legal.
        '''
        if not self.legality: return True
        if format is None:
            return False in self.legality.values()
        else:
            return self.legality[format]

    def is_reaction(self) -> bool:
        '''
        Whether this card is an attack or defense reaction card.

        Returns:
          Whether the card contains the _Attack Reaction_ or _Defense Reaction_ types.
        '''
        return self.is_attack_reaction() or self.is_defense_reaction()

    def is_red(self) -> bool:
        '''
        Whether this is a red card.

        Returns:
          Whether this card pitches for 1 resource.
        '''
        return self.pitch == 1 if isinstance(self.pitch, int) else False

    def is_token(self) -> bool:
        '''
        Whether this card is a token card.

        Returns:
          Whether the card contains the _Token_ type.
        '''
        return 'Token' in self.types

    def is_weapon(self) -> bool:
        '''
        Whether this card is a weapon card.

        Returns:
          Whether the card contains the _Weapon_ type.
        '''
        return 'Weapon' in self.types

    def is_yellow(self) -> bool:
        '''
        Whether this is a yellow card.

        Returns:
          Whether this card pitches for 2 resources.
        '''
        return self.pitch == 2 if isinstance(self.pitch, int) else False

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

        Returns:
          The `dict` keys as `list[str]`, corresponding to the possible fields of the card.
        '''
        return list(self.__dict__.keys())

    def rarity_names(self) -> list[str]:
        '''
        Returns the full names of the rarities associated with this card.

        Returns:
          A `list` of card rarity names associated with the card.
        '''
        return [RARITIES[r] for r in self.rarities]

    def render(self, heading_level: str = '###', icon_size: int = 11) -> Any:
        '''
        Renders this card into a markdown representation.

        Args:
          heading_level: Specifies the initial heading level of the card.
          icon_size: Specified the target width of icon images.

        Returns:
          The IPython-rendered markdown output.
        '''
        mdstr = f'{heading_level} {self.name} _({self.type_text})_\n\n'
        if not self.body is None:
            with_images = self.body
            for k, v in ICON_CODE_IMAGE_URLS.items():
                with_images = with_images.replace(k, f'<img src="{v}" alt="{k}" width="{icon_size}"/>')
            mdstr += f'{with_images}\n\n'
        if not self.flavor_text is None:
            mdstr += f'{self.flavor_text}\n\n'
        mdstr += '| Attribute | Value |\n|---|---|\n'
        if not self.power is None:
            mdstr += f'| Attack Power | {self.power} |\n'
        if not self.defense is None:
            mdstr += f'| Defense | {self.defense} |\n'
        if not self.health is None:
            mdstr += f'| Health | {self.health} |\n'
        if not self.intelligence is None:
            mdstr += f'| Intelligence | {self.intelligence} |\n'
        if not self.pitch is None:
            mdstr += f'| Pitch Value | {self.pitch} |\n'
        if not self.cost is None:
            mdstr += f'| Resource Cost | {self.cost} |\n'
        return display(Markdown(mdstr))

    def render_body(self, icon_size: int = 11) -> Any:
        '''
        Renders the body text of this card as markdown output.

        Args:
          icon_size: Specified the target width of icon images.

        Returns:
          The IPython-rendered markdown output.
        '''
        if self.body is None: return 'Specified card does not have any body text.'
        with_images = self.body
        for k, v in ICON_CODE_IMAGE_URLS.items():
            with_images = with_images.replace(k, f'<img src="{v}" alt="{k}" width="{icon_size}"/>')
        return display(Markdown(with_images))

    def tcgplayer_url(self) -> str:
        '''
        Computes the [TCG Player](https://www.tcgplayer.com/) URL for the card.

        Returns:
          The URL used to search for the card on TCG Player.
        '''
        return TCGPLAYER_BASE_URL + self.name

    def to_dict(self) -> dict[str, Any]:
        '''
        Converts this card into a raw python dictionary.

        Returns:
          A copy of the raw `dict` representation of the card.
        '''
        return copy.deepcopy(self.__dict__)

    def to_json(self) -> str:
        '''
        Computes the card's JSON string representation.

        Returns:
          A JSON string representation of the card.
        '''
        return json.dumps(self.__dict__, indent=JSON_INDENT)

    def to_series(self) -> Series:
        '''
        Converts the card into a [pandas Series
        object](https://pandas.pydata.org/docs/reference/series.html).

        Returns:
          A pandas `Series` object associated with the card.
        '''
        return Series(self.to_dict())

__getitem__(key)

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

Parameters:

Name Type Description Default
key str

The name of the class attribute to fetch.

required

Returns:

Type Description
Any

The value associated with the specified field.

Source code in fab/card.py
 96
 97
 98
 99
100
101
102
103
104
105
106
def __getitem__(self, key: str) -> Any:
    '''
    Allows one to access fields of a card via dictionary syntax.

    Args:
      key: The name of the class attribute to fetch.

    Returns:
      The value associated with the specified field.
    '''
    return self.__dict__[key]

__hash__()

Computes the hash representation of the card.

Returns:

Type Description
Any

The hash representation of the card.

Source code in fab/card.py
108
109
110
111
112
113
114
115
def __hash__(self) -> Any:
    '''
    Computes the hash representation of the card.

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

__str__()

Computes the JSON string representation of the card.

This is an alias of the to_json() method.

Returns:

Type Description
str

The JSON string representation of the card.

Source code in fab/card.py
117
118
119
120
121
122
123
124
125
126
def __str__(self) -> str:
    '''
    Computes the JSON string representation of the card.

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

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

from_full_name(full_name, catalog=None) staticmethod

Creates a new card from its full name.

Note

To instantiate the card this way, a card catalog (CardList) must be provided, defaulting to card.CARD_CATALOG.

Parameters:

Name Type Description Default
full_name str

The full name of the card (including pitch value, if applicable).

required
catalog Optional[CardList]

The card catalog to use as a reference, defaulting to card.CARD_CATALOG if None.

None

Returns:

Type Description
Card

A new Card object.

Source code in fab/card.py
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
@staticmethod
def from_full_name(full_name: str, catalog: Optional[CardList] = None) -> Card:
    '''
    Creates a new card from its full name.

    Note:
      To instantiate the card this way, a card catalog (`CardList`) must be
      provided, defaulting to `card.CARD_CATALOG`.

    Args:
      full_name: The full name of the card (including pitch value, if applicable).
      catalog: The card catalog to use as a reference, defaulting to `card.CARD_CATALOG` if `None`.

    Returns:
      A new `Card` object.
    '''
    _catalog = CARD_CATALOG if catalog is None else catalog
    if _catalog is None: raise Exception('specified card catalog has not been initialized')
    grouped = _catalog.group(by='full_name')
    if not full_name in grouped:
        raise Exception(f'specified card catalog does not contain a card will full name "{full_name}"')
    return copy.deepcopy(grouped[full_name][0])

from_identifier(identifier, catalog=None) staticmethod

Creates a new card from its identifier.

Note

To instantiate the card this way, a card catalog (CardList) must be provided, defaulting to card.CARD_CATALOG.

Parameters:

Name Type Description Default
identifier str

The identifier of the card.

required
catalog Optional[CardList]

The card catalog to use as a reference, defaulting to card.CARD_CATALOG if None.

None

Returns:

Type Description
Card

A new Card object.

Source code in fab/card.py
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
@staticmethod
def from_identifier(identifier: str, catalog: Optional[CardList] = None) -> Card:
    '''
    Creates a new card from its identifier.

    Note:
      To instantiate the card this way, a card catalog (`CardList`) must be
      provided, defaulting to `card.CARD_CATALOG`.

    Args:
      identifier: The identifier of the card.
      catalog: The card catalog to use as a reference, defaulting to `card.CARD_CATALOG` if `None`.

    Returns:
      A new `Card` object.
    '''
    _catalog = CARD_CATALOG if catalog is None else catalog
    if _catalog is None: raise Exception('specified card catalog has not been initialized')
    for card in _catalog:
        if identifier in card.identifiers:
            return copy.deepcopy(card)
    raise Exception(f'no card in catalog found with identifier "{identifier}"')

from_json(jsonstr) staticmethod

Creates a new card from the specified JSON string.

Parameters:

Name Type Description Default
jsonstr str

The JSON string representation to parse.

required

Returns:

Type Description
Card

A new Card object.

Source code in fab/card.py
174
175
176
177
178
179
180
181
182
183
184
185
@staticmethod
def from_json(jsonstr: str) -> Card:
    '''
    Creates a new card from the specified JSON string.

    Args:
      jsonstr: The JSON string representation to parse.

    Returns:
      A new `Card` object.
    '''
    return Card(**json.loads(jsonstr))

image(height=314, index=-1, width=225)

Display an image of this card, optionally providing an alternative index to use.

Parameters:

Name Type Description Default
height int

The height to scale the resulting image to, in pixels.

314
index int

The target image_urls index to fetch image data for.

-1
width int

The width to scale the resulting image to, in pixels.

225

Returns:

Type Description
Any

The image representation of the card.

Source code in fab/card.py
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
def image(self, height: int = 314, index: int = -1, width: int = 225) -> Any:
    '''
    Display an image of this card, optionally providing an alternative
    index to use.

    Args:
      height: The height to scale the resulting image to, in pixels.
      index: The target `image_urls` index to fetch image data for.
      width: The width to scale the resulting image to, in pixels.

    Returns:
      The image representation of the card.
    '''
    if not self.image_urls: return 'No images available'
    return display(Image(self.image_urls[index], height=height, width=width))

is_action()

Whether this card is an action card.

Returns:

Type Description
bool

Whether the card contains the Action type.

Source code in fab/card.py
203
204
205
206
207
208
209
210
def is_action(self) -> bool:
    '''
    Whether this card is an action card.

    Returns:
      Whether the card contains the _Action_ type.
    '''
    return 'Action' in self.types

is_attack()

Whether this card is an attack card.

Returns:

Type Description
bool

Whether the card contains the Attack type.

Source code in fab/card.py
212
213
214
215
216
217
218
219
def is_attack(self) -> bool:
    '''
    Whether this card is an attack card.

    Returns:
      Whether the card contains the _Attack_ type.
    '''
    return 'Attack' in self.types

is_attack_reaction()

Whether this card is an attack reaction card.

Returns:

Type Description
bool

Whether the card contains the Attack Reaction type.

Source code in fab/card.py
221
222
223
224
225
226
227
228
def is_attack_reaction(self) -> bool:
    '''
    Whether this card is an attack reaction card.

    Returns:
      Whether the card contains the _Attack Reaction_ type.
    '''
    return 'Attack Reaction' in self.types

is_aura()

Whether this card is an aura card.

Returns:

Type Description
bool

Whether the card contains the Aura type.

Source code in fab/card.py
230
231
232
233
234
235
236
237
def is_aura(self) -> bool:
    '''
    Whether this card is an aura card.

    Returns:
      Whether the card contains the _Aura_ type.
    '''
    return 'Aura' in self.types

is_blue()

Whether this is a blue card.

Returns:

Type Description
bool

Whether this card pitches for 3 resources.

Source code in fab/card.py
239
240
241
242
243
244
245
246
def is_blue(self) -> bool:
    '''
    Whether this is a blue card.

    Returns:
      Whether this card pitches for 3 resources.
    '''
    return self.pitch == 3 if isinstance(self.pitch, int) else False

is_defense_reaction()

Whether this card is a defense reaction card.

Returns:

Type Description
bool

Whether the card contains the Defense Reaction type.

Source code in fab/card.py
248
249
250
251
252
253
254
255
def is_defense_reaction(self) -> bool:
    '''
    Whether this card is a defense reaction card.

    Returns:
      Whether the card contains the _Defense Reaction_ type.
    '''
    return 'Defense Reaction' in self.types

is_equipment()

Whether this card is an equipment card.

Returns:

Type Description
bool

Whether the card contains the Equipment type.

Source code in fab/card.py
257
258
259
260
261
262
263
264
def is_equipment(self) -> bool:
    '''
    Whether this card is an equipment card.

    Returns:
      Whether the card contains the _Equipment_ type.
    '''
    return 'Equipment' in self.types

is_hero()

Whether this card is a hero card.

Returns:

Type Description
bool

Whether the card contains the Hero type.

Source code in fab/card.py
266
267
268
269
270
271
272
273
def is_hero(self) -> bool:
    '''
    Whether this card is a hero card.

    Returns:
      Whether the card contains the _Hero_ type.
    '''
    return 'Hero' in self.types

is_instant()

Whether this card is an instant card.

Returns:

Type Description
bool

Whether the card contains the Instant type.

Source code in fab/card.py
275
276
277
278
279
280
281
282
def is_instant(self) -> bool:
    '''
    Whether this card is an instant card.

    Returns:
      Whether the card contains the _Instant_ type.
    '''
    return 'Instant' in self.types

is_item()

Whether this card is an item card.

Returns:

Type Description
bool

Whether the card contains the Item type.

Source code in fab/card.py
284
285
286
287
288
289
290
291
def is_item(self) -> bool:
    '''
    Whether this card is an item card.

    Returns:
      Whether the card contains the _Item_ type.
    '''
    return 'Item' in self.types

Whether this card is legal for the specified format, or if format is None, returns False if this card is banned in any format.

Parameters:

Name Type Description Default
format Optional[str]

The code of the card format to check, or None to check all formats.

None

Returns:

Type Description
bool

Whether the card is legal.

Source code in fab/card.py
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
def is_legal(self, format: Optional[str] = None) -> bool:
    '''
    Whether this card is legal for the specified format, or if `format` is
    `None`, returns `False` if this card is banned in _any_ format.

    Args:
      format: The code of the card format to check, or `None` to check all formats.

    Returns:
      Whether the card is legal.
    '''
    if not self.legality: return True
    if format is None:
        return False in self.legality.values()
    else:
        return self.legality[format]

is_reaction()

Whether this card is an attack or defense reaction card.

Returns:

Type Description
bool

Whether the card contains the Attack Reaction or Defense Reaction types.

Source code in fab/card.py
310
311
312
313
314
315
316
317
def is_reaction(self) -> bool:
    '''
    Whether this card is an attack or defense reaction card.

    Returns:
      Whether the card contains the _Attack Reaction_ or _Defense Reaction_ types.
    '''
    return self.is_attack_reaction() or self.is_defense_reaction()

is_red()

Whether this is a red card.

Returns:

Type Description
bool

Whether this card pitches for 1 resource.

Source code in fab/card.py
319
320
321
322
323
324
325
326
def is_red(self) -> bool:
    '''
    Whether this is a red card.

    Returns:
      Whether this card pitches for 1 resource.
    '''
    return self.pitch == 1 if isinstance(self.pitch, int) else False

is_token()

Whether this card is a token card.

Returns:

Type Description
bool

Whether the card contains the Token type.

Source code in fab/card.py
328
329
330
331
332
333
334
335
def is_token(self) -> bool:
    '''
    Whether this card is a token card.

    Returns:
      Whether the card contains the _Token_ type.
    '''
    return 'Token' in self.types

is_weapon()

Whether this card is a weapon card.

Returns:

Type Description
bool

Whether the card contains the Weapon type.

Source code in fab/card.py
337
338
339
340
341
342
343
344
def is_weapon(self) -> bool:
    '''
    Whether this card is a weapon card.

    Returns:
      Whether the card contains the _Weapon_ type.
    '''
    return 'Weapon' in self.types

is_yellow()

Whether this is a yellow card.

Returns:

Type Description
bool

Whether this card pitches for 2 resources.

Source code in fab/card.py
346
347
348
349
350
351
352
353
def is_yellow(self) -> bool:
    '''
    Whether this is a yellow card.

    Returns:
      Whether this card pitches for 2 resources.
    '''
    return self.pitch == 2 if isinstance(self.pitch, int) else False

keys()

Returns the dictionary keys associated with this card class.

Returns:

Type Description
list[str]

The dict keys as list[str], corresponding to the possible fields of the card.

Source code in fab/card.py
355
356
357
358
359
360
361
362
def keys(self) -> list[str]:
    '''
    Returns the dictionary keys associated with this card class.

    Returns:
      The `dict` keys as `list[str]`, corresponding to the possible fields of the card.
    '''
    return list(self.__dict__.keys())

rarity_names()

Returns the full names of the rarities associated with this card.

Returns:

Type Description
list[str]

A list of card rarity names associated with the card.

Source code in fab/card.py
364
365
366
367
368
369
370
371
def rarity_names(self) -> list[str]:
    '''
    Returns the full names of the rarities associated with this card.

    Returns:
      A `list` of card rarity names associated with the card.
    '''
    return [RARITIES[r] for r in self.rarities]

render(heading_level='###', icon_size=11)

Renders this card into a markdown representation.

Parameters:

Name Type Description Default
heading_level str

Specifies the initial heading level of the card.

'###'
icon_size int

Specified the target width of icon images.

11

Returns:

Type Description
Any

The IPython-rendered markdown output.

Source code in fab/card.py
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
def render(self, heading_level: str = '###', icon_size: int = 11) -> Any:
    '''
    Renders this card into a markdown representation.

    Args:
      heading_level: Specifies the initial heading level of the card.
      icon_size: Specified the target width of icon images.

    Returns:
      The IPython-rendered markdown output.
    '''
    mdstr = f'{heading_level} {self.name} _({self.type_text})_\n\n'
    if not self.body is None:
        with_images = self.body
        for k, v in ICON_CODE_IMAGE_URLS.items():
            with_images = with_images.replace(k, f'<img src="{v}" alt="{k}" width="{icon_size}"/>')
        mdstr += f'{with_images}\n\n'
    if not self.flavor_text is None:
        mdstr += f'{self.flavor_text}\n\n'
    mdstr += '| Attribute | Value |\n|---|---|\n'
    if not self.power is None:
        mdstr += f'| Attack Power | {self.power} |\n'
    if not self.defense is None:
        mdstr += f'| Defense | {self.defense} |\n'
    if not self.health is None:
        mdstr += f'| Health | {self.health} |\n'
    if not self.intelligence is None:
        mdstr += f'| Intelligence | {self.intelligence} |\n'
    if not self.pitch is None:
        mdstr += f'| Pitch Value | {self.pitch} |\n'
    if not self.cost is None:
        mdstr += f'| Resource Cost | {self.cost} |\n'
    return display(Markdown(mdstr))

render_body(icon_size=11)

Renders the body text of this card as markdown output.

Parameters:

Name Type Description Default
icon_size int

Specified the target width of icon images.

11

Returns:

Type Description
Any

The IPython-rendered markdown output.

Source code in fab/card.py
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
def render_body(self, icon_size: int = 11) -> Any:
    '''
    Renders the body text of this card as markdown output.

    Args:
      icon_size: Specified the target width of icon images.

    Returns:
      The IPython-rendered markdown output.
    '''
    if self.body is None: return 'Specified card does not have any body text.'
    with_images = self.body
    for k, v in ICON_CODE_IMAGE_URLS.items():
        with_images = with_images.replace(k, f'<img src="{v}" alt="{k}" width="{icon_size}"/>')
    return display(Markdown(with_images))

tcgplayer_url()

Computes the TCG Player URL for the card.

Returns:

Type Description
str

The URL used to search for the card on TCG Player.

Source code in fab/card.py
423
424
425
426
427
428
429
430
def tcgplayer_url(self) -> str:
    '''
    Computes the [TCG Player](https://www.tcgplayer.com/) URL for the card.

    Returns:
      The URL used to search for the card on TCG Player.
    '''
    return TCGPLAYER_BASE_URL + self.name

to_dict()

Converts this card into a raw python dictionary.

Returns:

Type Description
dict[str, Any]

A copy of the raw dict representation of the card.

Source code in fab/card.py
432
433
434
435
436
437
438
439
def to_dict(self) -> dict[str, Any]:
    '''
    Converts this card into a raw python dictionary.

    Returns:
      A copy of the raw `dict` representation of the card.
    '''
    return copy.deepcopy(self.__dict__)

to_json()

Computes the card's JSON string representation.

Returns:

Type Description
str

A JSON string representation of the card.

Source code in fab/card.py
441
442
443
444
445
446
447
448
def to_json(self) -> str:
    '''
    Computes the card's JSON string representation.

    Returns:
      A JSON string representation of the card.
    '''
    return json.dumps(self.__dict__, indent=JSON_INDENT)

to_series()

Converts the card into a pandas Series object.

Returns:

Type Description
Series

A pandas Series object associated with the card.

Source code in fab/card.py
450
451
452
453
454
455
456
457
458
def to_series(self) -> Series:
    '''
    Converts the card into a [pandas Series
    object](https://pandas.pydata.org/docs/reference/series.html).

    Returns:
      A pandas `Series` object associated with the card.
    '''
    return Series(self.to_dict())