Class: Xcov::Target
Instance Attribute Summary collapse
-
#coverage ⇒ Object
Returns the value of attribute coverage.
-
#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_color, #displayable_coverage, #id
Class Method Summary collapse
- .calculate_coverage(files) ⇒ Object
-
.map(dictionary) ⇒ Object
Class methods.
Instance Method Summary collapse
- #html_value ⇒ Object
-
#initialize(name, coverage, files) ⇒ Target
constructor
A new instance of Target.
- #print_description ⇒ Object
Methods inherited from Base
#create_coverage_color, #create_displayable_coverage, create_id, #create_summary, template
Constructor Details
#initialize(name, coverage, files) ⇒ Target
Returns a new instance of Target.
11 12 13 14 15 16 17 18 |
# File 'lib/xcov/model/target.rb', line 11 def initialize (name, coverage, files) @name = CGI::escapeHTML(name) @coverage = coverage @files = files @displayable_coverage = self.create_displayable_coverage @coverage_color = self.create_coverage_color @id = Target.create_id(name) end |
Instance Attribute Details
#coverage ⇒ Object
Returns the value of attribute coverage.
7 8 9 |
# File 'lib/xcov/model/target.rb', line 7 def coverage @coverage end |
#file_templates ⇒ Object
Returns the value of attribute file_templates.
9 10 11 |
# File 'lib/xcov/model/target.rb', line 9 def file_templates @file_templates end |
#files ⇒ Object
Returns the value of attribute files.
8 9 10 |
# File 'lib/xcov/model/target.rb', line 8 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
.calculate_coverage(files) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/xcov/model/target.rb', line 48 def self.calculate_coverage (files) coverage = 0 non_ignored_files = files.select { |file| !file.ignored } non_ignored_files.each { |file| coverage += file.coverage } coverage = coverage / non_ignored_files.count unless non_ignored_files.empty? coverage end |
.map(dictionary) ⇒ Object
Class methods
38 39 40 41 42 43 44 45 46 |
# File 'lib/xcov/model/target.rb', line 38 def self.map (dictionary) name = dictionary["name"] files = dictionary["files"].map { |file| Source.map(file)} files = files.sort! { |lhs, rhs| lhs.coverage <=> rhs.coverage } .sort! { |lhs, rhs| (lhs.ignored ? 1:0) <=> (rhs.ignored ? 1:0) } coverage = Target.calculate_coverage(files) Target.new(name, coverage, files) end |
Instance Method Details
#html_value ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/xcov/model/target.rb', line 27 def html_value @file_templates = "" @files.each do |file| @file_templates << file.html_value end Function.template("target").result(binding) end |
#print_description ⇒ Object
20 21 22 23 24 25 |
# File 'lib/xcov/model/target.rb', line 20 def print_description puts "\t#{@name} (#{@coverage})" @files.each do |file| file.print_description end end |