class Rubycrap::Reporter
Attributes
crap_methods[R]
crap_methods_by_score[R]
Public Class Methods
new(crap_methods)
click to toggle source
# File lib/rubycrap/reporter.rb, line 6 def initialize(crap_methods) @crap_methods = crap_methods @crap_methods_by_score = crap_methods.sort_by { |k| -k[:crap_score] } end
Public Instance Methods
console()
click to toggle source
# File lib/rubycrap/reporter.rb, line 15 def console crap_methods_by_score[0..10].each do |element| puts formated_result(element) end end
html()
click to toggle source
# File lib/rubycrap/reporter.rb, line 11 def html File.open("CRAP.html", 'w') { |file| file.write(build_html) } end
Private Instance Methods
build_html()
click to toggle source
# File lib/rubycrap/reporter.rb, line 23 def build_html html = Array.new(0) html.push('<script src="https://code.jquery.com/jquery-2.2.2.min.js" integrity="sha256-36cp2Co+/62rEAAYHLmRCPIych47CvdM+uTBJwSzWjI=" crossorigin="anonymous"></script>') html.push('<script src="https://cdn.datatables.net/1.10.11/js/jquery.dataTables.js" crossorigin="anonymous"></script>') html.push('<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.11/css/jquery.dataTables.min.css">') html.push('<script type="text/javascript">') html.push(' $(document).ready(function(){') html.push(' $(\'#myTable\').DataTable();') html.push(' });') html.push('</script>') html.push('<table id="myTable">') html.push('<thead>') html.push(' <tr>') html.push(' <th>methodname</th>') html.push(' <th>flog_score</th>') html.push(' <th>filepath</th>') html.push(' <th>startline</th>') html.push(' <th>method_coverage</th>') html.push(' <th>crap_score</th>') html.push(' </tr>') html.push('</thead>') html.push('<tbody>') html.push('') @crap_methods_by_score.each do |element| html.push('<tr>') html.push(" <td>#{element[:methodname]}</td>") html.push(" <td>#{element[:flog_score]}</td>") html.push(" <td>#{element[:filepath]}</td>") html.push(" <td>#{element[:startline]}</td>") html.push(" <td>#{element[:method_coverage]}</td>") html.push(" <td>#{element[:crap_score]}</td>") html.push('</tr>') end html.push('</tbody>') html.push('</table>') html.join("\n") end
crap_score()
click to toggle source
# File lib/rubycrap/reporter.rb, line 67 def crap_score @crap_element[:crap_score].round.to_s.ljust(6) end
file_path()
click to toggle source
# File lib/rubycrap/reporter.rb, line 75 def file_path @crap_element[:filepath] end
formated_result(element)
click to toggle source
# File lib/rubycrap/reporter.rb, line 62 def formated_result(element) @crap_element = element "#{crap_score} | #{method_name} | #{file_path}:#{start_line}" end
method_name()
click to toggle source
# File lib/rubycrap/reporter.rb, line 71 def method_name @crap_element[:methodname].ljust(50) end
start_line()
click to toggle source
# File lib/rubycrap/reporter.rb, line 79 def start_line @crap_element[:startline] end