Skip to content

Commit

Permalink
search: normalize gender
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdecaf committed Jan 15, 2025
1 parent b08903a commit 99cec9a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
21 changes: 21 additions & 0 deletions internal/prepare/prepare_gender.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package prepare

import (
"strings"

"github.com/moov-io/watchman/pkg/search"
)

func NormalizeGender(input string) search.Gender {
v := strings.ToLower(strings.TrimSpace(input))

switch v {
case "m", "male", "man", "guy":
return search.GenderMale

case "f", "female", "woman", "gal", "girl":
return search.GenderFemale
}

return search.GenderUnknown
}
29 changes: 29 additions & 0 deletions internal/prepare/prepare_gender_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package prepare

import (
"testing"

"github.com/moov-io/watchman/pkg/search"

"github.com/stretchr/testify/require"
)

func TestPrepare_NormalizeGender(t *testing.T) {
cases := []struct {
input string
expected search.Gender
}{
{"M", search.GenderMale},
{"Male", search.GenderMale},
{"guy", search.GenderMale},
{"F", search.GenderFemale},
{"FEMALE", search.GenderFemale},
{"Girl", search.GenderFemale},
}
for _, tc := range cases {
t.Run(tc.input, func(t *testing.T) {
got := NormalizeGender(tc.input)
require.Equal(t, tc.expected, got)
})
}
}
3 changes: 2 additions & 1 deletion internal/search/api_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"
"time"

"github.com/moov-io/watchman/internal/prepare"
"github.com/moov-io/watchman/pkg/address"
"github.com/moov-io/watchman/pkg/search"

Expand Down Expand Up @@ -139,7 +140,7 @@ func readSearchRequest(r *http.Request) (search.Entity[search.Value], error) {
req.Person = &search.Person{
Name: req.Name,
AltNames: q["altNames"],
Gender: search.Gender(strings.TrimSpace(q.Get("gender"))),
Gender: prepare.NormalizeGender(q.Get("gender")),
BirthDate: readDate(q.Get("birthDate")),
DeathDate: readDate(q.Get("deathDate")),
Titles: q["titles"],
Expand Down

0 comments on commit 99cec9a

Please sign in to comment.