aboutsummaryrefslogtreecommitdiffstats
path: root/skate/schema.go
diff options
context:
space:
mode:
Diffstat (limited to 'skate/schema.go')
-rw-r--r--skate/schema.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/skate/schema.go b/skate/schema.go
index d35272e..a9b6a96 100644
--- a/skate/schema.go
+++ b/skate/schema.go
@@ -122,6 +122,37 @@ func RefToRelease(ref *Ref) (*Release, error) {
return &release, nil
}
+// ReleaseToUnstructured tries to render a sensible string, e.g. for frontend
+// display of unmatched and other relations. Some examples:
+// https://guides.lib.uw.edu/c.php?g=341448&p=4076094 No specific style, just
+// try to be readable.
+func ReleaseToUnstructured(r *Release) string {
+ var (
+ buf bytes.Buffer
+ names = make([]string, len(r.Contribs))
+ )
+ for i := 0; i < len(r.Contribs); i++ {
+ names[i] = r.Contribs[i].RawName
+ }
+ fmt.Fprintf(&buf, "%s", strings.Join(names, ", "))
+ if r.Title != "" {
+ if buf.Len() > 0 {
+ fmt.Fprintf(&buf, ". ")
+ }
+ fmt.Fprintf(&buf, `%s`, r.Title)
+ }
+ if len(r.Subtitle()) > 0 {
+ fmt.Fprintf(&buf, ": %s", strings.Join(r.Subtitle(), " "))
+ }
+ if r.ContainerName != "" {
+ if buf.Len() > 0 {
+ fmt.Fprintf(&buf, ". ")
+ }
+ fmt.Fprintf(&buf, `%s`, r.ContainerName)
+ }
+ return buf.String()
+}
+
// ParseIsbn tries to find and validate ISBN from unstructured data. Returns a
// list of unique, unsorted and validated ISBN13, e.g. 9780123838520.
func ParseIsbn(s string) []string {