-
-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f0db8a3
commit 48fdcb6
Showing
5 changed files
with
140 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,68 @@ | ||
class Text: | ||
|
||
def __init__(self, lines=None): | ||
self._lines = lines or [] | ||
def __init__(self, path=None): | ||
self._parts = [] if path is None else path.split('/') | ||
|
||
@property | ||
def top(self): | ||
def __getitem__(self, key): | ||
try: | ||
return self._lines[0] | ||
except IndexError: | ||
part = self._parts[key] | ||
except (IndexError, ValueError): | ||
return "" | ||
else: | ||
return part | ||
|
||
def get_line(self, index): | ||
return self._format_line(self[index]) | ||
|
||
@property | ||
def top(self): | ||
return self.get_line(0) | ||
|
||
@property | ||
def bottom(self): | ||
try: | ||
return self._lines[1] | ||
except IndexError: | ||
return "" | ||
return self.get_line(1) | ||
|
||
@property | ||
def lines(self): | ||
lines = [] | ||
|
||
for part in self: | ||
if part: | ||
line = self._format_line(part) | ||
lines.append(line) | ||
else: | ||
break | ||
|
||
return lines | ||
|
||
@property | ||
def path(self): | ||
paths = [] | ||
|
||
for line in self.lines: | ||
path = self._format_path(line) | ||
paths.append(path) | ||
|
||
return '/'.join(paths) | ||
|
||
@staticmethod | ||
def _format_line(part): | ||
chars = [] | ||
|
||
upper = True | ||
for char in part: | ||
if char in ('_', '-'): | ||
chars.append(' ') | ||
upper = True | ||
else: | ||
if char.isupper(): | ||
if not upper: | ||
chars.append(' ') | ||
chars.append(char.upper()) | ||
upper = char.isupper() | ||
|
||
return ''.join(chars) | ||
|
||
@staticmethod | ||
def _format_path(line): | ||
return line.replace(' ', '-').lower() |
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
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