xlo 0.0.1.2 → 0.0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/xlo.rb +62 -50
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c0006b3d5fb544c57f3a5e389cbbb0ddf9a1a233
4
- data.tar.gz: 84d85fbb541be99e8d6a5622a829b2815b2ada07
3
+ metadata.gz: d00cebfb60d2fc43a0352b5459ece2ad2552ad8c
4
+ data.tar.gz: fc26cafa24e6c45efe222d45155e732f01e05ece
5
5
  SHA512:
6
- metadata.gz: f538524342298e3ce361f35d99525b7e28025a57fd5e5e5a732342b62d3f7cfb7f8c52def397b13cb7062ac5e292dddf302725652249139f024122945380ea86
7
- data.tar.gz: b753e93c2cbde0edcdd6fb3259c10bf3fcd81a8f03b79f5b19f983e63d86974e17ec4cee03498988593c7a2befa5f2cde2d38a726c610295998a31f53e730e7d
6
+ metadata.gz: 397058a1543886648f7db64835536e8a0698789c6236f5d04ac427b2c254958cc393ace3cee45be7c18827023378576884321c16ffc6dadab61a85b5a84d8cea
7
+ data.tar.gz: 9fb918377f7cb4680e56b30fa442a844da10ee9aabe160b50fffbcd268cee88d6e1121f2f2b377aedf130e16c617f1cf99e00d006027ac2a7961686aecd9d2e2
data/lib/xlo.rb CHANGED
@@ -1,88 +1,100 @@
1
1
  require 'open3'
2
2
 
3
3
  class Xlo
4
+ attr_accessor :rnv, :xmllint, :csv
4
5
 
5
- def self.rnv_wrapper (_rnc, _dir)
6
- list = []
6
+ def initialize(_file)
7
+ @rnv = []
8
+ @xmllint = []
9
+ @csv = File.new(_file,"w+")
10
+ @csv << "type; error; freq; files \n"
11
+ @error = {}
12
+ end
13
+
14
+ def rnv_wrapper (_rnc, _dir)
7
15
  Dir[_dir + "/" + "*.xml"].each do |file|
8
16
  stdout = Open3.capture3("rnv #{_rnc} #{file}")
9
17
  stdout = stdout[1].split("\n")
10
18
  stdout.each do |line|
11
- if (line.include?("error") && !line.include?("are invalid"))
12
- list << line
13
- end
19
+ @rnv << line
14
20
  end
15
21
  end
16
- return list
17
22
  end
18
23
 
19
- def self.rnv_error_dict (_list)
20
- error = {}
21
- _list.each do |el|
22
- type = el.split("error")[1].split(" ")[1]
23
- if (type == "attribute" || type == "element")
24
- key = type + "; " + el[/\^.*/][1..-1]
25
- filename = File.basename(el.split("error")[0])
26
- filename[filename.length - 2] = ""
27
- else
28
- type = "other"
29
- key = type + "; " + el.split("error:")[1]
30
- filename = File.basename(el.split("error")[0])
31
- filename[filename.length - 2] = ""
32
- end
33
- if (error.has_key?(key))
34
- error[key] << " || " + filename
35
- else
36
- error[key] = filename
24
+ def rnv_aggregate
25
+ @rnv.each do |el|
26
+ if (el.include?("error") && !el.include?("are invalid"))
27
+
28
+ type = el.split("error")[1].split(" ")[1]
29
+
30
+ if (type == "attribute" || type == "element")
31
+ key = type + "; " + el[/\^.*/][1..-1]
32
+ filename = File.basename(el.split("error")[0])
33
+ filename[filename.length - 2] = ""
34
+ else
35
+ type = "other"
36
+ key = type + "; " + el.split("error:")[1]
37
+ filename = File.basename(el.split("error")[0])
38
+ filename[filename.length - 2] = ""
39
+ end
40
+
41
+ if (@error.has_key?(key))
42
+ @error[key] << " || " + filename
43
+ else
44
+ @error[key] = filename
45
+ end
46
+
37
47
  end
38
48
  end
39
- return error
40
49
  end
41
50
 
42
- def self.xmllint_wrapper (_dir)
43
- list = []
51
+ def xmllint_wrapper (_dir)
44
52
  Dir[_dir + "/" + "*.xml"].each do |file|
45
53
  stdout = Open3.capture3("xmllint #{file}")
46
54
  stdout = stdout[1].split("\n")
47
55
  stdout.each do |line|
48
- if (!line.include?(" ^"))
49
- list << line.chomp
50
- end
56
+ @xmllint << line
51
57
  end
52
58
  end
59
+ end
53
60
 
54
- error = {}
55
- list = list.values_at(* list.each_index.select {|i| i.even?})
56
- list.each do |el|
61
+ def xmllint_aggregate
62
+
63
+ @xmllint.delete_if {|el| el.include?("^")}
64
+ @xmllint.map { |e| e.chomp }
65
+ @xmllint = @xmllint.values_at(* @xmllint.each_index.select {|i| i.even?})
66
+ @xmllint.each do |el|
57
67
  split_el = el.split(" ")
58
- type = el[/element|attribute/]
68
+ type = el[/element|attribute|parser error/]
59
69
  key = type + ";" + el.split(":")[-1]
60
70
  filename = File.basename(split_el[0])[0..-2]
61
- if (error.has_key?(key))
62
- error[key] << " || " + filename
71
+ if (@error.has_key?(key))
72
+ @error[key] << " || " + filename
63
73
  else
64
- error[key] = filename
74
+ @error[key] = filename
65
75
  end
66
76
  end
67
- return error
77
+ end
78
+
79
+ def csv_writer
80
+ @error.each do |entry|
81
+ line = entry.dup
82
+ line[-1] = line[-1].split("||")[0..50].join
83
+ freq = entry[1].split("||").length
84
+ @csv.write(line.insert(1, freq.to_s).join(";")[0..-2] + "\n" )
85
+ end
68
86
  end
69
87
 
70
88
  def self.main(_rnv_arg,_folder_arg)
71
89
 
72
- error = []
73
- f = File.new("error.csv", "w+")
74
- f.write("type; error; freq; files \n")
90
+ xlo = Xlo.new(File.new("error.csv", "w+"))
75
91
 
76
- list = self.rnv_wrapper(_rnv_arg, _folder_arg)
77
- error << self.rnv_error_dict(list)
92
+ xlo.rnv_wrapper(_rnv_arg, _folder_arg)
93
+ xlo.rnv_aggregate
78
94
 
79
- error << self.xmllint_wrapper(_folder_arg)
95
+ xlo.xmllint_wrapper(_folder_arg)
96
+ xlo.xmllint_aggregate
80
97
 
81
- error.each do |dict|
82
- dict.each do |entry|
83
- freq = entry[1].split("||").length.to_s
84
- f.write(entry.insert(1, freq).join("; ")[0..-2] + "\n" )
85
- end
86
- end
98
+ xlo.csv_writer
87
99
  end
88
100
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xlo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.2
4
+ version: 0.0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Meoni