Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added fullName and updated parsedNameSuffix handling #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ internal enum class FieldKey {
GIVEN_NAME_ALIAS,
SUFFIX_ALIAS,
SUFFIX,
SUFFIX_2,

MIDDLE_NAME_TRUNCATION,
FIRST_NAME_TRUNCATION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import java.util.*
* A model for storing the parsed license data.
* */
data class License(
var fullName: String? = null,
var firstName: String? = null,
var middleNames: List<String> = listOf(),
var lastName: String? = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ open class DLParser(val data: String) {
FieldKey.INVENTORY_CONTROL_NUMBER to "DCK",
FieldKey.LAST_NAME_ALIAS to "DBN",
FieldKey.GIVEN_NAME_ALIAS to "DBG",
FieldKey.SUFFIX to "DBS", //.name toDO toOr DCU
FieldKey.SUFFIX to "DBS",
FieldKey.SUFFIX_2 to "DCU",
FieldKey.WEIGHT_RANGE to "DCE",
FieldKey.RACE to "DCL",
FieldKey.STANDARD_VEHICLE_CODE to "DCM",
Expand Down Expand Up @@ -114,6 +115,7 @@ open class DLParser(val data: String) {
val version = versionNumber
val parser = versionParser
return License(
parser.parsedFullName,
parser.parsedFirstName,
parser.parsedMiddleNames,
parser.parsedLastName,
Expand Down Expand Up @@ -189,6 +191,31 @@ open class DLParser(val data: String) {
return rawValue == "1"
}

protected open val parsedFullName: String
get() {
var hasFirstNameField = false
val firstNameParts: List<String>
if (parseString(FieldKey.FIRST_NAME) != null) {
firstNameParts = listOf(parseString(FieldKey.FIRST_NAME)!!)
hasFirstNameField = true
}
else {
firstNameParts = parseString(FieldKey.GIVEN_NAME)?.split(",")?.map { it.trim() }
?: parseString(FieldKey.DRIVER_LICENSE_NAME)?.split(",")?.map { it.trim() }
?: listOf()
}

val nameParts = mutableListOf<String>()
nameParts.addAll(firstNameParts)
if (hasFirstNameField) {
nameParts.addAll(parsedMiddleNames)
}
if (parsedLastName != null) nameParts.add(parsedLastName!!)
if (parsedNameSuffix != null) nameParts.add(parsedNameSuffix?.rawValue!!)

return nameParts.distinct().joinToString(" ")
}

protected open val parsedFirstName
get() =
parseString(FieldKey.FIRST_NAME)
Expand Down Expand Up @@ -219,7 +246,7 @@ open class DLParser(val data: String) {

protected open val parsedNameSuffix: NameSuffix?
get() {
return NameSuffix.of(parseString(FieldKey.SUFFIX) ?: return null)
return NameSuffix.of(parseString(FieldKey.SUFFIX) ?: parseString(FieldKey.SUFFIX_2) ?: return null)
}

internal open fun parseTruncation(key: FieldKey): Truncation? {
Expand Down