Skip to content

Commit

Permalink
Deserialize EntryHeader parameters
Browse files Browse the repository at this point in the history
The EntryHeader would set the map of all its parameters as its name
member, which semantically does not make sense and requires a user to
parse the name member itself to find the actual name of the header.

Deserialize the EntryHeader according to the TSP to set members
"name", "tooltip" and "data_type".
  • Loading branch information
awendelin-work committed Jul 3, 2024
1 parent 29ba74a commit b7c8acf
Showing 1 changed file with 37 additions and 4 deletions.
41 changes: 37 additions & 4 deletions tsp/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,32 @@

"""Entry classes file."""

from enum import Enum

from tsp.output_element_style import OutputElementStyle

ID_KEY = "id"
PARENT_ID_KEY = "parentId"
LABELS_KEY = "labels"
STYLE_KEY = "style"
HEADER_NAME_KEY = "name"
HEADER_DATA_TYPE_KEY = "dataType"
HEADER_TOOLTIP_KEY = "tooltip"
UNKNOWN_ID = -1
NAME_KEY = "name"
TOOLTIP_KEY = "tooltip"

# pylint: disable=too-few-public-methods

class EntryHeaderDataType(Enum):
'''
The data types of a column entry.
'''
NUMBER = "NUMBER"
BINARY_NUMBER = "BINARY_NUMBER"
TIMESTAMP = "TIMESTAMP"
DURATION = "DURATION"
STRING = "STRING"
TIME_RANGE = "TIME_RANGE"


class EntryHeader:
'''
Expand All @@ -43,9 +56,29 @@ class EntryHeader:

def __init__(self, params):
'''
Displayed name
Constructor
'''
self.name = params

# Name for this header.
if HEADER_NAME_KEY in params:
self.name = params.get(HEADER_NAME_KEY)
del params[HEADER_NAME_KEY]
else:
self.name = None

# Tooltip for this header.
if HEADER_TOOLTIP_KEY in params:
self.tooltip = params.get(HEADER_TOOLTIP_KEY)
del params[HEADER_TOOLTIP_KEY]
else:
self.tooltip = None

# Data type for this header.
if HEADER_DATA_TYPE_KEY in params:
self.data_type = EntryHeaderDataType(params.get(HEADER_DATA_TYPE_KEY))
del params[HEADER_DATA_TYPE_KEY]
else:
self.data_type = None


class Entry:
Expand Down

0 comments on commit b7c8acf

Please sign in to comment.