Class: Couve::Parser
- Inherits:
-
Object
- Object
- Couve::Parser
- Defined in:
- lib/couve/parser.rb
Instance Method Summary collapse
-
#initialize(coverage) ⇒ Parser
constructor
A new instance of Parser.
- #to_html ⇒ Object
- #to_markdown ⇒ Object
Constructor Details
#initialize(coverage) ⇒ Parser
Returns a new instance of Parser.
7 8 9 10 11 |
# File 'lib/couve/parser.rb', line 7 def initialize(coverage) @coverage = JSON.parse(coverage, symbolize_names: true) @coverage[:source_files].reject! { |file| file[:covered_percent] == 100 } @coverage[:source_files].sort_by! { |file| file[:covered_percent] } end |
Instance Method Details
#to_html ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/couve/parser.rb', line 13 def to_html <<~HTML <html> <body> <div class="container mt-5"> <h1 class="display-5"> Coverage problems </h1> <table class="table table-hover mt-5"> <thead> <tr> <th class="col-1" colspan="2">Coverage</th> <th class="col-7">File</th> <th class="col-3">Not covered lines</th> </tr> </thead> #{body} </table> </div> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous"> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script> </body> </html> HTML end |
#to_markdown ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/couve/parser.rb', line 41 def to_markdown rows = @coverage[:source_files].map do |source_file| percentage = source_file[:covered_percent].round(2) indicator = percentage_indicator(percentage) "| #{indicator} | #{percentage}% | #{source_file[:name]} | #{not_covered_lines(source_file)} |" end <<~MARKDOWN ## Coverage problems | Rating | Coverage | File | Not covered lines | | :---: | ---: | :--- | :--- | #{rows.join("\n")} MARKDOWN end |