Skip to content

Commit

Permalink
feat: add some useful dunder methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravencentric committed Jul 8, 2024
1 parent f63c792 commit bb4074e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/pyanilist/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

class ParentModel(BaseModel):
"""
Parent Model that stores the global configuration
All models ahead will inherit from this
Parent Model that stores the global configuration.
All models ahead will inherit from this.
"""

model_config = ConfigDict(
Expand All @@ -49,6 +49,9 @@ class MediaTitle(ParentModel):
native: str | None = None
"""Official title in its native language"""

def __str__(self) -> str:
return self.english or self.romaji or self.native # type: ignore


class FuzzyDate(ParentModel):
"""Naive date object that allows for incomplete date values (fuzzy)."""
Expand Down Expand Up @@ -97,6 +100,12 @@ def as_int(self) -> FuzzyDateInt:

return int(f"{year}{month}{day}")

def __str__(self) -> str:
return self.iso_format()

def __int__(self) -> int:
return self.as_int()


class MediaTrailer(ParentModel):
"""Media trailer or advertisement."""
Expand Down

0 comments on commit bb4074e

Please sign in to comment.