Skip to content

Commit

Permalink
Fixed bug in GetValues
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorcorrea committed Oct 16, 2019
1 parent eb9bd18 commit cc27e99
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions marc/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package marc

import (
"fmt"
"strings"
)

// Record is a struct representing a MARC record. It has a Fields slice
Expand Down Expand Up @@ -113,14 +114,15 @@ func (r Record) GetValue(tag string, subfield string) string {
func (r Record) GetValues(tag string, subfield string) []string {
values := []string{}
for _, field := range r.FieldsByTag(tag) {
if subfield != "" {
if strings.TrimSpace(subfield) == "" {
// No subfield indicated, return the string version of the field
values = append(values, field.String())
}
for _, sub := range field.SubFields {
if sub.Code == subfield {
// Return the first instance of the requested subfield
values = append(values, sub.Value)
} else {
for _, sub := range field.SubFields {
if sub.Code == subfield {
// Return the first instance of the requested subfield
values = append(values, sub.Value)
}
}
}
}
Expand Down

0 comments on commit cc27e99

Please sign in to comment.