Class: Xcov::Source

Inherits:
Base
  • Object
show all
Defined in:
lib/xcov/model/source.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#coverage_color, #displayable_coverage, #id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#coverage_emoji, #create_coverage_color, #create_displayable_coverage, create_id, #create_summary, template

Constructor Details

#initialize(name, location, coverage, coveredLines, executableLines, functions, lines = nil) ⇒ Source

Returns a new instance of Source.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/xcov/model/source.rb', line 17

def initialize(name, location, coverage, coveredLines, executableLines, functions, lines = nil)
  @name = CGI::escapeHTML(name)
  @location = CGI::escapeHTML(location)
  @coverage = coverage
  @coveredLines = coveredLines
  @executableLines = executableLines
  @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.message "Ignoring #{name} coverage".yellow
  end
end

Instance Attribute Details

#coverageObject

Returns the value of attribute coverage.



10
11
12
# File 'lib/xcov/model/source.rb', line 10

def coverage
  @coverage
end

#coveredLinesObject

Returns the value of attribute coveredLines.



11
12
13
# File 'lib/xcov/model/source.rb', line 11

def coveredLines
  @coveredLines
end

#executableLinesObject

Returns the value of attribute executableLines.



12
13
14
# File 'lib/xcov/model/source.rb', line 12

def executableLines
  @executableLines
end

#function_templatesObject

Returns the value of attribute function_templates.



14
15
16
# File 'lib/xcov/model/source.rb', line 14

def function_templates
  @function_templates
end

#functionsObject

Returns the value of attribute functions.



13
14
15
# File 'lib/xcov/model/source.rb', line 13

def functions
  @functions
end

#ignoredObject

Returns the value of attribute ignored.



9
10
11
# File 'lib/xcov/model/source.rb', line 9

def ignored
  @ignored
end

#linesObject

Returns the value of attribute lines.



15
16
17
# File 'lib/xcov/model/source.rb', line 15

def lines
  @lines
end

#locationObject

Returns the value of attribute location.



7
8
9
# File 'lib/xcov/model/source.rb', line 7

def location
  @location
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/xcov/model/source.rb', line 6

def name
  @name
end

#typeObject

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



72
73
74
75
76
77
78
79
80
81
# File 'lib/xcov/model/source.rb', line 72

def self.map(dictionary)
  name = dictionary["name"]
  location = dictionary["location"]
  coverage = dictionary["coverage"]
  coveredLines = dictionary["coveredLines"]
  executableLines = dictionary["executableLines"]
  functions = dictionary["functions"].map { |function| Function.map(function)}
  lines = map_lines(dictionary["lines"])
  Source.new(name, location, coverage, coveredLines, executableLines, functions, lines)
end

.map_lines(dictionaries) ⇒ Object



83
84
85
86
# File 'lib/xcov/model/source.rb', line 83

def self.map_lines(dictionaries)
  return nil if dictionaries.nil?
  dictionaries.map { |line| Line.map(line) }
end

.type(name) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/xcov/model/source.rb', line 88

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_valueObject



43
44
45
46
47
48
49
50
# File 'lib/xcov/model/source.rb', line 43

def html_value
  @function_templates = ""
  @functions.each do |function|
    @function_templates << function.html_value
  end

  Function.template("file").result(binding)
end

#json_valueObject



56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/xcov/model/source.rb', line 56

def json_value
  value = {
    "name" => @name,
    "path" => @location,
    "coverage" => @coverage,
    "type" => @type,
    "functions" => @functions ? @functions.map{ |function| function.json_value } : []
  }
  if @ignored then
    value["ignored"] = true
  end
  return value
end

#markdown_valueObject



52
53
54
# File 'lib/xcov/model/source.rb', line 52

def markdown_value
  "#{@name} | `#{@displayable_coverage}` | #{coverage_emoji}\n"
end


36
37
38
39
40
41
# File 'lib/xcov/model/source.rb', line 36

def print_description
  puts "\t\t#{@name} (#{@coverage})"
  @functions.each do |function|
    function.print_description
  end
end