-
Notifications
You must be signed in to change notification settings - Fork 2
/
SierraPhysicalLocationType.scala
77 lines (69 loc) · 2.15 KB
/
SierraPhysicalLocationType.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package weco.catalogue.source_model.sierra.rules
import grizzled.slf4j.Logging
import weco.catalogue.internal_model.locations.{
LocationType,
PhysicalLocationType
}
import weco.sierra.models.identifiers.TypedSierraRecordNumber
object SierraPhysicalLocationType extends Logging {
def fromName(
id: TypedSierraRecordNumber,
name: String
): Option[PhysicalLocationType] =
name.toLowerCase match {
case lowerCaseName
if lowerCaseName.hasSubstring(
"archives & mss well.coll",
"at digitisation",
"by appointment",
"closed stores",
"conservation",
"early printed books",
"iconographic collection",
"offsite",
"unrequestable"
) =>
Some(LocationType.ClosedStores)
case lowerCaseName
if lowerCaseName.hasSubstring(
"biographies",
"folios",
"history of medicine",
"journals",
"medical collection",
"medicine & society collection",
"open shelves",
"quick ref collection",
"quick ref. collection",
"rare materials room",
"student coll"
) =>
Some(LocationType.OpenShelves)
case lowerCaseName
if lowerCaseName.hasSubstring(
"exhibition"
) =>
Some(LocationType.OnExhibition)
case lowerCaseName if lowerCaseName == "" || lowerCaseName == "none" =>
None
case _ =>
if (!knownUnknownLocations.contains(name)) {
warn(
s"${id.withCheckDigit}: Unable to map Sierra location name to LocationType: $name"
)
}
None
}
// This is a list of location names that we know can't be mapped to a location type,
// for which we don't log a warning to avoid cluttering up logs.
//
// https://en.wikipedia.org/wiki/There_are_known_knowns
private val knownUnknownLocations = Set(
"bound in above",
"Contained in above"
)
implicit class StringOps(s: String) {
def hasSubstring(substrings: String*): Boolean =
substrings.exists { s.contains }
}
}