-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Using enums for browser for extendabilty
- Loading branch information
1 parent
bd45a68
commit 65b096c
Showing
2 changed files
with
11 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,14 @@ | ||
from bing_browser import BingTextBrowser | ||
from google_browser import GoogleTextBrowser | ||
from .bing_browser import BingTextBrowser | ||
from .google_browser import GoogleTextBrowser | ||
|
||
|
||
class TextBrowserCreator: | ||
"""Creator class for creating different text browsers at runtime. Make sure to add newly registered browsers here""" | ||
class TextBrowserEnum: | ||
"""Enum class for creating different text browsers. Make sure to add newly registered browsers here""" | ||
|
||
browser_classes = { | ||
'BingTextBrowser': BingTextBrowser, | ||
'GoogleTextBrowser': GoogleTextBrowser | ||
} | ||
bing = BingTextBrowser | ||
google = GoogleTextBrowser | ||
|
||
@classmethod | ||
def create_browser(cls, name: str): | ||
"""Factory method to create a text browser instance based on the name.""" | ||
if name in cls.browser_classes: | ||
return cls.browser_classes[name]() | ||
else: | ||
raise ValueError(f"Unknown browser name: {name}") | ||
def get_browser(cls, browser_str): | ||
return getattr(cls, browser_str) | ||
|