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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d07072e108fdd8e7dbe6bcae377fef9ad99c506b44bacc7655d4f0d7f2389805
4
- data.tar.gz: 123536f3e3fe7940be40382902214fe0c5649e9547cbe912c40d38056416efbf
3
+ metadata.gz: 6b0fb72e2ed02f090ec93652025685f180a23f697422861d47aa7467c71d5d11
4
+ data.tar.gz: 6a1ace7c1e73a17b1f92770bdfe42130259a399ee2326c167cb7bb3a2b6e8df4
5
5
  SHA512:
6
- metadata.gz: e0f2a2a0497707f7994a9a8b0b5ca25f2d67ecdd053b4503f5a02103677919270741b0facf895dd26184b69e4a5e59da4c3d41db81ee36dafdd53182705eccbc
7
- data.tar.gz: 3c6df1d9a4ab66bfd1dae7594212886c8999e91fd125051b105133f436bcb6fb34baa7ff5cdf80a75cf5ac782e17a0aaec8abdc3c12ea74fd7a7e59106a67876
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
- prev_line_special = false
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 |line|
19
- if line.lstrip.start_with?("|")
20
- array_to_parse << line
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
- new_line, prev_line_special = cleaned_line(line, prev_line_special)
27
- results << new_line
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
- ## We simply add a newline at the end of the line if needed
90
- ##============================================================##
91
- def cleaned_line(line, prev_line_special)
92
- cleaned = line.rstrip
93
- blank_line = line.gsub("\n", "").empty?
94
- special = cleaned.lstrip.start_with?("*", "-", "+")
95
- new_line = "#{"\n" if prev_line_special && !blank_line}#{cleaned}\n"
96
- prev_line_special = special
97
- [new_line, prev_line_special]
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
@@ -1,3 +1,3 @@
1
1
  module ImmosquareCleaner
2
- VERSION = "0.1.61".freeze
2
+ VERSION = "0.1.62".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: immosquare-cleaner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.61
4
+ version: 0.1.62
5
5
  platform: ruby
6
6
  authors:
7
7
  - immosquare