]> git.lizzy.rs Git - go-anidb.git/blobdiff - misc/episode.go
anidb: Correct cache key for LID.MyListEntry
[go-anidb.git] / misc / episode.go
index c5d41a88e3e566beaebbd9a8285947f08b64c596..920ae93c8481a6cfea1f37be1031e4c0b30d4f2c 100644 (file)
@@ -10,6 +10,9 @@ import (
 type EpisodeContainer interface {
        // Returns true if this EpisodeContainer is equivalent or a superset of the given EpisodeContainer
        ContainsEpisodes(EpisodeContainer) bool
+       // Returns a channel meant for iterating with for/range.
+       // Sends all contained episodes in order.
+       Episodes() chan Episode
 }
 
 type Formatter interface {
@@ -83,7 +86,7 @@ func scale(i int) int {
 }
 
 // Converts the Episode into AniDB API episode format.
-func (ep *Episode) String() string {
+func (ep Episode) String() string {
        return ep.Format(1)
 }
 
@@ -95,6 +98,15 @@ func (ep *Episode) scale() int {
        return scale(ep.Number)
 }
 
+func (ep *Episode) Episodes() chan Episode {
+       ch := make(chan Episode, 1)
+       if ep != nil {
+               ch <- *ep
+       }
+       close(ch)
+       return ch
+}
+
 // Returns true if ec is an Episode and is identical to this episode,
 // or if ec is a single episode EpisodeRange / EpisodeList that
 // contain only this episode.
@@ -117,7 +129,7 @@ func (ep *Episode) ContainsEpisodes(ec EpisodeContainer) bool {
        return false
 }
 
-func (ep *Episode) Format(width int) string {
+func (ep Episode) Format(width int) string {
        if ep.Part < 0 { // whole episode
                return fmt.Sprintf("%s%0"+strconv.Itoa(width)+"d", ep.Type, ep.Number)
        }