// Package foodchain handles I knew a lady... song.
package foodchain
import (
"strings"
)
var animals = []string{
"fly", "spider", "bird", "cat", "dog", "goat", "cow", "horse",
}
// second line
var second = []string{
"", // fly
"", // spider
"\nHow absurd to swallow a bird!",
"\nImagine that, to swallow a cat!",
"\nWhat a hog, to swallow a dog!",
"\nJust opened her throat and swallowed a goat!",
"\nI don't know how she swallowed a cow!",
"", // horse
}
const wring = "wriggled and jiggled and tickled inside her."
func Verse(num int) string {
var ret = strings.Builder{}
if num != 8 {
ret.WriteString("I know an old lady who swallowed a ")
ret.WriteString(animals[num-1])
ret.WriteByte('.')
if num == 2 {
ret.WriteString("\nIt ")
ret.WriteString(wring)
}
ret.WriteString(second[num-1])
for i := num; i > 1; i-- {
ret.WriteString("\nShe swallowed the ")
ret.WriteString(animals[i-1])
ret.WriteString(" to catch the ")
ret.WriteString(animals[i-2])
if i == 3 {
ret.WriteString(" that ")
ret.WriteString(wring)
} else {
ret.WriteByte('.')
}
}
ret.WriteString("\nI don't know why she swallowed the fly. Perhaps she'll die.")
} else {
ret.WriteString("I know an old lady who swallowed a horse.")
ret.WriteString("\nShe's dead, of course!")
}
return ret.String()
}
func Verses(lower, upper int) string {
var ret = strings.Builder{}
for i := lower; i <= upper; i++ {
ret.WriteString(Verse(i))
if i != upper {
ret.WriteString("\n\n")
}
}
return ret.String()
}
func Song() string {
return Verses(1, 8)
}