Module: SQT

Defined in:
lib/sqt.rb

Overview

Sarbotte Quality Tool v1.0 Copyright Sarbotte Designs Open Sarbotte License

Defined Under Namespace

Classes: Sqt

Class Method Summary collapse

Class Method Details

.sarbotteCurl(url, depth) ⇒ Object



93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/sqt.rb', line 93

def self.sarbotteCurl(url, depth)
  require 'curb'
  result = []
  if depth.nil?
    http = Curl.get(url)
    file = http.body_str
    result = Sqt.buildResult(url, file)
  else
    result = Sqt.sarbotteCurlWithDepth(url, depth, [])
  end
  return result
end

.sarbotteFile(file) ⇒ Object



85
86
87
# File 'lib/sqt.rb', line 85

def self.sarbotteFile(file)
  Sqt.buildResult(file, File.read(file))
end

.sarbottePath(path, extension) ⇒ Object



80
81
82
83
# File 'lib/sqt.rb', line 80

def self.sarbottePath(path, extension)
  path.gsub!('\\', File::SEPARATOR)
  Dir["#{path}/**/*\.#{extension}"].map{ |p| Sqt.buildResult(p, File.read(p))}
end

.sarbottePrint(filesProperties, options) ⇒ Object

Affiche en console les résultats



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/sqt.rb', line 107

def self.sarbottePrint(filesProperties, options)
  puts "\nSarbotte Quality Tool\n".colorize( :cyan )
  if options[:path] then
    puts "Chemin : " + options[:path] + "\n\n"
  end
  if filesProperties.size > 1 then
    average = filesProperties.reduce(0) { |total, fP| total + fP[:sqi] }.to_f / filesProperties.size
    print "Moyenne : "
    puts "#{'%.2f' % average}".colorize( average < 0.5 ? :red : average < 0.8 ? :yellow : :green )
    puts ""
  end
  puts "Fichiers : "
  filesProperties.each do |fP|
    sqi = fP[:sqi]
    print "  #{fP[:uri].gsub(options[:path] && options[:path] != "." ? options[:path] : "", "")} : "
    print "#{'%.2f' % fP[:sqi]}".colorize( sqi < 50 ? :red : sqi < 80 ? :yellow : :green )
    puts " (#{fP[:jsAndCssLength]}/#{fP[:totalLength]})"
  end
end

.sarbotteString(string) ⇒ Object



89
90
91
# File 'lib/sqt.rb', line 89

def self.sarbotteString(string)
  Sqt.buildResult("", string)
end

.sarbotteWrite(filesProperties, options) ⇒ Object

Écrit dans un fichier les résultats



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/sqt.rb', line 128

def self.sarbotteWrite(filesProperties, options)
  result = "Sarbotte Quality Tool\n\n"
  if options[:path] then
    result += "Chemin : " + options[:path] + "\n\n"
  end
  if filesProperties.size > 1 then
    average = filesProperties.reduce(0) { |total, fP| total + fP[:sqi] }.to_f / filesProperties.size
    result +=  "Moyenne : "
    result += "#{'%.2f' % average}\n\n"
  end
  result += "Fichiers : \n"
  filesProperties.each do |fP|
    sqi = fP[:sqi]
    result += "  #{fP[:uri].gsub(options[:path] && options[:path] != "." ? options[:path] : "", "")} : "
    result += "#{'%.2f' % fP[:sqi]}"
    result += "(#{fP[:jsAndCssLength]}/#{fP[:totalLength]})\n"
  end
  File.open(options[:fileName], 'w') {|f| f.write(result) }
end