Skip to content

Commit c3e04f3

Browse files
Add CSV and Markdown export methods to LineCounter class
1 parent d738fe1 commit c3e04f3

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include README.md
2+
include requirements.txt

extliner/main.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,30 @@ def _build_result(self) -> Dict[str, Dict[str, int]]:
4545

4646
def to_json(self, data: Dict) -> str:
4747
return json.dumps(data, indent=2)
48+
49+
def to_dict(self, data: Dict) -> Dict:
50+
return data
51+
52+
def to_csv(self, data: Dict) -> str:
53+
import csv
54+
from io import StringIO
55+
56+
output = StringIO()
57+
writer = csv.writer(output)
58+
writer.writerow(["Extension", "With Spaces", "Without Spaces"])
59+
60+
for ext, counts in data.items():
61+
writer.writerow([ext, counts["with_spaces"], counts["without_spaces"]])
62+
63+
return output.getvalue()
64+
65+
66+
def to_markdown(self, data: Dict) -> str:
67+
output = "| Extension | With Spaces | Without Spaces |\n"
68+
output += "|-----------|-------------|----------------|\n"
69+
70+
for ext, counts in data.items():
71+
output += f"| {ext} | {counts['with_spaces']} | {counts['without_spaces']} |\n"
72+
73+
return output
74+

0 commit comments

Comments
 (0)