Convert into class

This commit is contained in:
Jose De Freitas 2021-02-23 15:15:43 -05:00
parent 34b6734b8c
commit f125957be7

View File

@ -6,35 +6,56 @@ with open(file_readme, 'r') as read_readme:
content_readme = read_readme.readlines() content_readme = read_readme.readlines()
def content_about(): class ContentAbout():
""" """
Looks for trailing slashes and words separated by commas at Contains methods for the detection of various
every "Content about:" section found in the readme.md file rules asigned to the "Content about:" sections.
(this is, the list itself). These methods edit the readme.md file (the awe-
some list) in-place if any of the rules isn't
met.
result (str): return value of the function. Attributes:
checker (str): detector of the line corresponding the file. checker (str): matches the "Content about:" string.
result (str): result of the operation.
""" """
result = 'No errors found.' checker = "Content about:"
checker = 'Content about:'
for line, value in enumerate(content_readme): def __init__(self):
if checker in value: self.result = "🟢 No errors found."
# Check for trailing slash
if value[-2] != '\\': def trailing_slash(self) -> str:
if value[-2] == ' ': """
content_readme[line] = value[:-1] + '\\' + '\n' Looks for backslash and the end of all the matching
with open(file_readme, 'w') as write_readme: lines ("Content about:" lines).
write_readme.writelines(content_readme) """
else:
content_readme[line] = value[:-1] + ' \\' + '\n' for line, value in enumerate(content_readme):
if self.checker in value:
last = value[-2]
if last != '\\':
if last == ' ':
content_readme[line] = f"{value[:-1]}\\\n"
else:
content_readme[line] = f"{value[:-1]} \\\n"
with open(file_readme, 'w') as write_readme: with open(file_readme, 'w') as write_readme:
write_readme.writelines(content_readme) write_readme.writelines(content_readme)
self.result = "🔴 Trailing slash wasn't found.\nFixed."
result = "Trailing slash wasn't found.\nFixed." return self.result
return result def comma_separated(self) -> str:
"""
Looks through all words in the section to check
if they're separated by a comma and a space
", ".
"""
# for line, value in enumerate(content_readme):
# if self.checker in value:
return self.result
print(content_about()) content_about = ContentAbout()
print(content_about.trailing_slash())