Class: Xlo
- Inherits:
-
Object
- Object
- Xlo
- Defined in:
- lib/xlo.rb
Instance Attribute Summary collapse
-
#csv ⇒ Object
Returns the value of attribute csv.
-
#rnv ⇒ Object
Returns the value of attribute rnv.
-
#xmllint ⇒ Object
Returns the value of attribute xmllint.
Class Method Summary collapse
Instance Method Summary collapse
- #csv_writer ⇒ Object
- #get_error ⇒ Object
-
#initialize(*args) ⇒ Xlo
constructor
A new instance of Xlo.
- #rnv_aggregate(_rnv) ⇒ Object
- #rnv_wrapper(_rnc, _file) ⇒ Object
- #run(_rnv_arg, _folder_arg, _pool_size = 8) ⇒ Object
- #xmllint_aggregate(_xmllint) ⇒ Object
- #xmllint_wrapper(_file) ⇒ Object
Constructor Details
#initialize(*args) ⇒ Xlo
Returns a new instance of Xlo.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/xlo.rb', line 7 def initialize(*args) @rnv = [] @xmllint = [] if args.size == 1 @csv = File.new(args[0],"w+") @csv << "type; error; freq; files \n" end @error = {} @mutex = Mutex.new end |
Instance Attribute Details
#csv ⇒ Object
Returns the value of attribute csv.
5 6 7 |
# File 'lib/xlo.rb', line 5 def csv @csv end |
#rnv ⇒ Object
Returns the value of attribute rnv.
5 6 7 |
# File 'lib/xlo.rb', line 5 def rnv @rnv end |
#xmllint ⇒ Object
Returns the value of attribute xmllint.
5 6 7 |
# File 'lib/xlo.rb', line 5 def xmllint @xmllint end |
Class Method Details
Instance Method Details
#csv_writer ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'lib/xlo.rb', line 90 def csv_writer @error.each do |entry| line = entry.dup line[-1] = line[-1].split("||")[0..50].join freq = entry[1].split("||").length @csv.write(line.insert(1, freq.to_s).join(";")[0..-2] + "\n" ) end end |
#get_error ⇒ Object
20 21 22 |
# File 'lib/xlo.rb', line 20 def get_error return @error end |
#rnv_aggregate(_rnv) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/xlo.rb', line 34 def rnv_aggregate(_rnv) _rnv.each do |el| if (el.include?("error") && !el.include?("are invalid")) type = el.split("error")[1].split(" ")[1] if (type == "attribute" || type == "element") key = type + "; " + el[/\^.*/][1..-1] filename = File.basename(el.split("error")[0]) filename[filename.length - 2] = "" else type = "other" key = type + "; " + el.split("error:")[1] filename = File.basename(el.split("error")[0]) filename[filename.length - 2] = "" end @mutex.synchronize do if (@error.has_key?(key)) @error[key] << " || " + filename else @error[key] = filename end end end end end |
#rnv_wrapper(_rnc, _file) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/xlo.rb', line 24 def rnv_wrapper (_rnc, _file) rnv = [] stdout = Open3.capture3("rnv #{_rnc} #{_file}") stdout = stdout[1].split("\n") stdout.each do |line| rnv << line end return rnv end |
#run(_rnv_arg, _folder_arg, _pool_size = 8) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/xlo.rb', line 99 def run(_rnv_arg, _folder_arg, _pool_size = 8) jobs = Queue.new Dir[_folder_arg + "/" + "*.xml"].each {|f| jobs.push f} workers = (_pool_size).times.map do Thread.new do while jobs.size != 0 file = jobs.pop rnv_aggregate(rnv_wrapper(_rnv_arg,file)) xmllint_aggregate(xmllint_wrapper(file)) end end end workers.map(&:join) end |
#xmllint_aggregate(_xmllint) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/xlo.rb', line 71 def xmllint_aggregate(_xmllint) _xmllint.delete_if {|el| el.include?("^")} _xmllint.map { |e| e.chomp } _xmllint = _xmllint.values_at(* _xmllint.each_index.select {|i| i.even?}) _xmllint.each do |el| split_el = el.split(" ") type = el[/element|attribute|parser error/] key = type + ";" + el.split(":")[-1] filename = File.basename(split_el[0])[0..-2] @mutex.synchronize do if (@error.has_key?(key)) @error[key] << " || " + filename else @error[key] = filename end end end end |
#xmllint_wrapper(_file) ⇒ Object
61 62 63 64 65 66 67 68 69 |
# File 'lib/xlo.rb', line 61 def xmllint_wrapper (_file) xmllint = [] stdout = Open3.capture3("xmllint #{_file}") stdout = stdout[1].split("\n") stdout.each do |line| xmllint << line end return xmllint end |