26 lines
628 B
Python
26 lines
628 B
Python
from image_prediction.formatter.formatter import Formatter
|
|
|
|
|
|
class Snake2CamelCaseKeyFormatter(Formatter):
|
|
|
|
@staticmethod
|
|
def __format_key(key):
|
|
|
|
if isinstance(key, str):
|
|
head, *tail = key.split("_")
|
|
return head + "".join(map(lambda s: s.title(), tail))
|
|
else:
|
|
return key
|
|
|
|
def __format(self, data):
|
|
|
|
if not isinstance(data, dict):
|
|
return data
|
|
|
|
keys_formatted = list(map(self.__format_key, data))
|
|
|
|
return dict(zip(keys_formatted, map(self.__format, data.values())))
|
|
|
|
def format(self, data):
|
|
return self.__format(data)
|