immosquare-cleaner 0.1.61 → 0.1.62
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/immosquare-cleaner/markdown.rb +31 -23
- data/lib/immosquare-cleaner/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b0fb72e2ed02f090ec93652025685f180a23f697422861d47aa7467c71d5d11
|
4
|
+
data.tar.gz: 6a1ace7c1e73a17b1f92770bdfe42130259a399ee2326c167cb7bb3a2b6e8df4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2953d75e8958df53dd5f8c665a6a16405287f59d6cd1513f2c7698147242a492c58aa3197270ced1e97249b387750a0072686e8ce0c6b6dd82ebcd7b2ea7e8c
|
7
|
+
data.tar.gz: 30efc05bb51de9db9cb4c74d37bd6cbc3eba27693e7ac4a70fff466f634776ff43b69bc9d126a4c5464c131ea45a4381d951726f5eaba18d8cbf3c6d7ebea875
|
@@ -2,29 +2,33 @@ module ImmosquareCleaner
|
|
2
2
|
module Markdown
|
3
3
|
class << self
|
4
4
|
|
5
|
-
|
6
|
-
##============================================================##
|
7
|
-
## we want to clean the markdown files to have a uniform style
|
8
|
-
## for the tables.
|
9
|
-
##============================================================##
|
10
5
|
def clean(file_path)
|
11
|
-
results
|
12
|
-
array_to_parse
|
13
|
-
|
6
|
+
results = []
|
7
|
+
array_to_parse = []
|
8
|
+
lines = []
|
14
9
|
|
15
10
|
##============================================================##
|
16
11
|
## We parse each line of the file
|
17
12
|
##============================================================##
|
18
|
-
File.foreach(file_path) do |
|
19
|
-
|
20
|
-
|
13
|
+
File.foreach(file_path) do |current_line|
|
14
|
+
##============================================================##
|
15
|
+
## We save the last line to know if we need to add a newline
|
16
|
+
##============================================================##
|
17
|
+
previous_line = lines.last
|
18
|
+
lines << current_line
|
19
|
+
|
20
|
+
##============================================================##
|
21
|
+
## We add the line to the array if it starts with a pipe
|
22
|
+
##============================================================##
|
23
|
+
if current_line.lstrip.start_with?("|")
|
24
|
+
array_to_parse << current_line
|
21
25
|
else
|
22
26
|
if !array_to_parse.empty?
|
23
27
|
results << cleaned_array(array_to_parse)
|
24
28
|
array_to_parse = []
|
25
29
|
end
|
26
|
-
|
27
|
-
results
|
30
|
+
new_lines = cleaned_line(previous_line, current_line)
|
31
|
+
results += new_lines
|
28
32
|
end
|
29
33
|
end
|
30
34
|
|
@@ -39,6 +43,10 @@ module ImmosquareCleaner
|
|
39
43
|
|
40
44
|
private
|
41
45
|
|
46
|
+
##============================================================##
|
47
|
+
## we want to clean the markdown files to have a uniform style
|
48
|
+
## for the tables.
|
49
|
+
##============================================================##
|
42
50
|
def cleaned_array(array_to_clean)
|
43
51
|
##============================================================##
|
44
52
|
## We split each line of the array and remove the empty cells
|
@@ -85,16 +93,16 @@ module ImmosquareCleaner
|
|
85
93
|
"#{formatted_rows.join("\n")}\n"
|
86
94
|
end
|
87
95
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
blank_line
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
[
|
96
|
+
def cleaned_line(previous_line, current_line)
|
97
|
+
return [current_line] if !previous_line
|
98
|
+
|
99
|
+
cleaned_current = current_line.rstrip
|
100
|
+
cleaned_previous = previous_line.rstrip
|
101
|
+
blank_line = current_line.gsub("\n", "").empty?
|
102
|
+
previous_is_list = cleaned_previous.lstrip.start_with?("*", "-", "+")
|
103
|
+
current_is_list = cleaned_current.lstrip.start_with?("*", "-", "+")
|
104
|
+
final = previous_is_list && !current_is_list && !blank_line ? ["\n"] : []
|
105
|
+
final << ["#{cleaned_current}\n"]
|
98
106
|
end
|
99
107
|
|
100
108
|
end
|