Skip to content
Open
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
43 changes: 42 additions & 1 deletion app/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from ..services.location.csbs import CSBSLocationService
from ..services.location.jhu import JhuLocationService
from ..services.location.nyt import NYTLocationService
from abc import ABCMeta, abstractmethod

# Mapping of services to data-sources.
DATA_SOURCES = {
Expand All @@ -10,7 +11,6 @@
"nyt": NYTLocationService(),
}


def data_source(source):
"""
Retrieves the provided data-source service.
Expand All @@ -19,3 +19,44 @@ def data_source(source):
:rtype: LocationService
"""
return DATA_SOURCES.get(source.lower())


class LocationAssembler:
"""The Director"""
builder = None

def setBuilder(self,builder):
self.builder = builder

def getSource(self):
product = LocationSource()
source = self.builder.getDataSource()
product.setDataSource(source)

class LocationSource:
"""The Product"""
def __init__(self):
self.datasource = None

def setDataSource(self, dataSource):
self.dataSource = dataSource

class LocationSourceBuilder(metaclass=ABCMeta):
"""The Interface"""
@abstractmethod
def getDataSource(self): pass

class JHUBuilder(LocationSourceBuilder):
"""The Concrete Builder"""
def getDataSource(self):
return DATA_SOURCES.get("jhu")

class CSBSBuilder(LocationSourceBuilder):
"""The Concrete Builder"""
def getDataSource(self):
return DATA_SOURCES.get("csbs")

class NYTBuilder(LocationSourceBuilder):
"""The Concrete Builder"""
def getDataSource(self):
return DATA_SOURCES.get("nyt")