Skip to content

Commit

Permalink
add top-level iterable
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgryan committed Nov 12, 2024
1 parent a2d56af commit c65587c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/detaf/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ def taf_encode(self) -> str:
parts.append(weather.taf_encode())
return " ".join(parts)

def __iter__(self):
yield "TAF"
if self.version != Version.ORIGINAL:
yield self.version
if self.icao_identifier:
yield self.icao_identifier
if self.issue_time:
yield self.issue_time
yield from self.weather_conditions


def parse(bulletin: str) -> TAF:
words = bulletin.strip().split()
Expand Down Expand Up @@ -289,6 +299,8 @@ def encode(item) -> str:
return encode_issue_time(item)
elif isinstance(item, period):
return encode_period(item)
elif isinstance(item, str):
return item
else:
return item.taf_encode()

Expand Down
4 changes: 4 additions & 0 deletions tests/test_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,7 @@ def test_parse_wx():
assert wx.parse("-DZ") == wx.Wx(
intensity=wx.Intensity.LIGHT, precipitation=wx.Precipitation.DRIZZLE
)


def test_iterable():
assert list(detaf.decode("TAF COR")) == ["TAF", detaf.Version.CORRECTED]

0 comments on commit c65587c

Please sign in to comment.