Class: Xcov::Target
Instance Attribute Summary collapse
-
#file_templates ⇒ Object
Returns the value of attribute file_templates.
-
#files ⇒ Object
Returns the value of attribute files.
-
#name ⇒ Object
Returns the value of attribute name.
Attributes inherited from Base
#coverage, #coverage_color, #displayable_coverage, #id
Class Method Summary collapse
- .by_coverage_with_ignored_at_the_end ⇒ Object
-
.map(dictionary) ⇒ Object
Class methods.
- .select_non_ignored_files(files) ⇒ Object
Instance Method Summary collapse
- #html_value ⇒ Object
-
#initialize(name, files) ⇒ Target
constructor
A new instance of Target.
- #json_value ⇒ Object
- #markdown_value ⇒ Object
- #print_description ⇒ Object
Methods inherited from Base
#coverage_emoji, #create_coverage_color, #create_displayable_coverage, create_id, #create_summary, template
Constructor Details
#initialize(name, files) ⇒ Target
Returns a new instance of Target.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/xcov/model/target.rb', line 10 def initialize(name, files) @name = CGI::escapeHTML(name) @files = files totalCoveredLines = files.reduce(0) { |acc, file| acc + file.coveredLines } totalExecutableLines = files.reduce(0) { |acc, file| acc + file.executableLines } @coverage = files.count == 0 || totalExecutableLines == 0 ? 0.0 : totalCoveredLines.to_f / totalExecutableLines.to_f @displayable_coverage = self.create_displayable_coverage @coverage_color = self.create_coverage_color @id = Target.create_id(name) end |
Instance Attribute Details
#file_templates ⇒ Object
Returns the value of attribute file_templates.
8 9 10 |
# File 'lib/xcov/model/target.rb', line 8 def file_templates @file_templates end |
#files ⇒ Object
Returns the value of attribute files.
7 8 9 |
# File 'lib/xcov/model/target.rb', line 7 def files @files end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/xcov/model/target.rb', line 6 def name @name end |
Class Method Details
.by_coverage_with_ignored_at_the_end ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/xcov/model/target.rb', line 65 def self.by_coverage_with_ignored_at_the_end lambda { |lhs, rhs| if lhs.ignored == rhs.ignored # sort by coverage if files are both ignored # or none of them are ignored (lhs.coverage <=> rhs.coverage) else # ignored files will come at the end (lhs.ignored ? 1:0) <=> (rhs.ignored ? 1:0) end } end |
.map(dictionary) ⇒ Object
Class methods
56 57 58 59 60 61 62 63 |
# File 'lib/xcov/model/target.rb', line 56 def self.map(dictionary) name = dictionary["name"] files = dictionary["files"].map { |file| Source.map(file)} files = files.sort &by_coverage_with_ignored_at_the_end non_ignored_files = Target.select_non_ignored_files(files) Target.new(name, non_ignored_files) end |
.select_non_ignored_files(files) ⇒ Object
78 79 80 |
# File 'lib/xcov/model/target.rb', line 78 def self.select_non_ignored_files(files) files.select { |file| !file.ignored } end |
Instance Method Details
#html_value ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/xcov/model/target.rb', line 28 def html_value @file_templates = "" @files.each do |file| @file_templates << file.html_value end Function.template("target").result(binding) end |
#json_value ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/xcov/model/target.rb', line 46 def json_value { "name" => @name, "coverage" => @coverage, "files" => @files ? @files.map{ |file| file.json_value } : [] } end |
#markdown_value ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/xcov/model/target.rb', line 37 def markdown_value markdown = "## Current coverage for #{@name} is `#{@displayable_coverage}`\n" return markdown << "✅ *No files affecting coverage found*\n\n---\n" if @files.empty? markdown << "Files changed | - | - \n--- | --- | ---\n" markdown << "#{@files.map { |file| file.markdown_value }.join("")}\n---\n" markdown end |
#print_description ⇒ Object
21 22 23 24 25 26 |
# File 'lib/xcov/model/target.rb', line 21 def print_description puts "\t#{@name} (#{@coverage})" @files.each do |file| file.print_description end end |