Top Level Namespace
Defined Under Namespace
Modules: Jsmetric
Classes: CCReport, ComplexityAnalyser, GraphAnalyser, JSLint, Report
Instance Method Summary
collapse
Instance Method Details
#strip_js(data) ⇒ Object
1
2
3
4
5
6
7
8
|
# File 'lib/utils.rb', line 1
def strip_js(data)
non_empty_strings = []
stripped_data = data.gsub(/('|").*?[^\\]\1/) { |m|
non_empty_strings.push $&
"!temp-string-replacement-#{non_empty_strings.size}!"
}
stripped_data.gsub(/\/\*.*?\*\//m, "\n").gsub(/\/\/.*$/, "").gsub(/( |\t)+$/, "").gsub(/\n+/, "\n").gsub(/!temp-string-replacement-([0-9]+)!/) { |m| non_empty_strings[$1.to_i] }
end
|
#word_freq_in(the_file) ⇒ Object
11
12
13
14
15
16
17
18
|
# File 'lib/utils.rb', line 11
def word_freq_in the_file
store = Hash.new
the_file.each_line { |line|
line.split.each { |word| store.has_key?(word) ? store[word] += 1 : store[word] = 1 }
}
store.sort { |a, b| a[1]<=>b[1] }
store
end
|