Class: Xcov::Source
Instance Attribute Summary collapse
-
#coverage ⇒ Object
Returns the value of attribute coverage.
-
#function_templates ⇒ Object
Returns the value of attribute function_templates.
-
#functions ⇒ Object
Returns the value of attribute functions.
-
#ignored ⇒ Object
Returns the value of attribute ignored.
-
#lines ⇒ Object
Returns the value of attribute lines.
-
#location ⇒ Object
Returns the value of attribute location.
-
#name ⇒ Object
Returns the value of attribute name.
-
#type ⇒ Object
Returns the value of attribute type.
Attributes inherited from Base
#coverage_color, #displayable_coverage, #id
Class Method Summary collapse
Instance Method Summary collapse
- #html_value ⇒ Object
-
#initialize(name, location, coverage, functions, lines = nil) ⇒ Source
constructor
A new instance of Source.
- #json_value ⇒ Object
- #markdown_value ⇒ Object
- #number_of_covered_lines ⇒ Object
- #number_of_executable_lines ⇒ 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, location, coverage, functions, lines = nil) ⇒ Source
Returns a new instance of Source.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/xcov/model/source.rb', line 15 def initialize(name, location, coverage, functions, lines = nil) @name = CGI::escapeHTML(name) @location = CGI::escapeHTML(location) @coverage = coverage @functions = functions @ignored = Xcov.ignore_handler.should_ignore_file_at_path(location) @displayable_coverage = self.create_displayable_coverage @coverage_color = self.create_coverage_color @id = Source.create_id(name) @type = Source.type(name) @lines = lines if @ignored UI. "Ignoring #{name} coverage".yellow end end |
Instance Attribute Details
#coverage ⇒ Object
Returns the value of attribute coverage.
10 11 12 |
# File 'lib/xcov/model/source.rb', line 10 def coverage @coverage end |
#function_templates ⇒ Object
Returns the value of attribute function_templates.
12 13 14 |
# File 'lib/xcov/model/source.rb', line 12 def function_templates @function_templates end |
#functions ⇒ Object
Returns the value of attribute functions.
11 12 13 |
# File 'lib/xcov/model/source.rb', line 11 def functions @functions end |
#ignored ⇒ Object
Returns the value of attribute ignored.
9 10 11 |
# File 'lib/xcov/model/source.rb', line 9 def ignored @ignored end |
#lines ⇒ Object
Returns the value of attribute lines.
13 14 15 |
# File 'lib/xcov/model/source.rb', line 13 def lines @lines end |
#location ⇒ Object
Returns the value of attribute location.
7 8 9 |
# File 'lib/xcov/model/source.rb', line 7 def location @location end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/xcov/model/source.rb', line 6 def name @name end |
#type ⇒ Object
Returns the value of attribute type.
8 9 10 |
# File 'lib/xcov/model/source.rb', line 8 def type @type end |
Class Method Details
.map(dictionary) ⇒ Object
Class methods
77 78 79 80 81 82 83 84 |
# File 'lib/xcov/model/source.rb', line 77 def self.map(dictionary) name = dictionary["name"] location = dictionary["location"] coverage = dictionary["coverage"] functions = dictionary["functions"].map { |function| Function.map(function)} lines = map_lines(dictionary["lines"]) Source.new(name, location, coverage, functions, lines) end |
.map_lines(dictionaries) ⇒ Object
86 87 88 89 |
# File 'lib/xcov/model/source.rb', line 86 def self.map_lines(dictionaries) return nil if dictionaries.nil? dictionaries.map { |line| Line.map(line) } end |
.type(name) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/xcov/model/source.rb', line 91 def self.type(name) types_map = { ".swift" => "swift", ".m" => "objc", ".cpp" => "cpp", ".mm" => "cpp" } extension = File.extname(name) type = types_map[extension] type = "objc" if type.nil? type end |
Instance Method Details
#html_value ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/xcov/model/source.rb', line 39 def html_value @function_templates = "" @functions.each do |function| @function_templates << function.html_value end Function.template("file").result(binding) end |
#json_value ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/xcov/model/source.rb', line 52 def json_value value = { "name" => @name, "coverage" => @coverage, "type" => @type, "functions" => @functions ? @functions.map{ |function| function.json_value } : [] } if @ignored then value["ignored"] = true end return value end |
#markdown_value ⇒ Object
48 49 50 |
# File 'lib/xcov/model/source.rb', line 48 def markdown_value "#{@name} | `#{@displayable_coverage}` | #{coverage_emoji}\n" end |
#number_of_covered_lines ⇒ Object
70 71 72 73 |
# File 'lib/xcov/model/source.rb', line 70 def number_of_covered_lines return 0 if lines.nil? || lines.empty? lines.select { |line| line.covered? }.count end |
#number_of_executable_lines ⇒ Object
65 66 67 68 |
# File 'lib/xcov/model/source.rb', line 65 def number_of_executable_lines return 0 if lines.nil? || lines.empty? lines.select { |line| line.executable }.count end |
#print_description ⇒ Object
32 33 34 35 36 37 |
# File 'lib/xcov/model/source.rb', line 32 def print_description puts "\t\t#{@name} (#{@coverage})" @functions.each do |function| function.print_description end end |