From 9f2c63a4e87a2638cc63620e6722fae494495dc6 Mon Sep 17 00:00:00 2001 From: Martin Czygan Date: Sat, 10 Jul 2021 03:13:20 +0200 Subject: schema: flesh our unstructured rendering --- skate/schema.go | 30 ++++++++++++++++++++++++++++++ skate/schema_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) (limited to 'skate') diff --git a/skate/schema.go b/skate/schema.go index a9b6a96..77460d1 100644 --- a/skate/schema.go +++ b/skate/schema.go @@ -150,6 +150,36 @@ func ReleaseToUnstructured(r *Release) string { } fmt.Fprintf(&buf, `%s`, r.ContainerName) } + if r.Volume != "" { + if buf.Len() > 0 { + fmt.Fprintf(&buf, ", ") + } + fmt.Fprintf(&buf, `vol. %s`, r.Volume) + } + if r.Issue != "" { + if buf.Len() > 0 { + fmt.Fprintf(&buf, ", ") + } + fmt.Fprintf(&buf, `no. %s`, r.Issue) + } + if r.ReleaseYear() > 0 { + if buf.Len() > 0 { + fmt.Fprintf(&buf, ", ") + } + fmt.Fprintf(&buf, `%s`, r.ReleaseYearString()) + } + if r.Pages != "" { + if buf.Len() > 0 { + fmt.Fprintf(&buf, ", ") + } + fmt.Fprintf(&buf, `pp. %s`, r.Pages) + } + if r.Publisher != "" { + if buf.Len() > 0 { + fmt.Fprintf(&buf, ", ") + } + fmt.Fprintf(&buf, `%s`, r.Publisher) + } return buf.String() } diff --git a/skate/schema_test.go b/skate/schema_test.go index a8f1ecf..cfffced 100644 --- a/skate/schema_test.go +++ b/skate/schema_test.go @@ -262,13 +262,39 @@ func TestReleaseToUnstructured(t *testing.T) { s string }{ {r: &Release{}, s: ""}, + {r: &Release{Volume: "12"}, s: "vol. 12"}, + {r: &Release{Volume: "12", Issue: "X"}, s: "vol. 12, no. X"}, + {r: &Release{Volume: "12", Issue: "X", ReleaseYearValue: "1999"}, s: "vol. 12, no. X, 1999"}, + {r: &Release{Volume: "12", ContainerName: "Solar", + ReleaseYearValue: "1999"}, s: "Solar, vol. 12, 1999"}, {r: &Release{ Title: "ABC", }, s: "ABC"}, + {r: &Release{ + Title: "ABC", + ReleaseYearValue: "2000", + }, s: "ABC, 2000"}, + {r: &Release{ + ContainerName: "Journal of Letters", + }, s: "Journal of Letters"}, + {r: &Release{ + ContainerName: "Journal of Letters", + }, s: "Journal of Letters"}, {r: &Release{ Title: "ABC", ContainerName: "Journal of Letters", }, s: "ABC. Journal of Letters"}, + {r: &Release{ + Title: "ABC", + ContainerName: "Journal of Letters", + Volume: "12", + Pages: "1-10", + }, s: "ABC. Journal of Letters, vol. 12, pp. 1-10"}, + {r: &Release{ + Title: "ABC", + ReleaseYearValue: "2010", + ContainerName: "Journal of Letters", + }, s: "ABC. Journal of Letters, 2010"}, {r: &Release{ Title: "ABC", ContainerName: "Journal of Letters", -- cgit v1.2.3