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

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

Constructor Details

#initialize(name, coverage, functions) ⇒ Source

Returns a new instance of Source.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/xcov/model/source.rb', line 13

def initialize (name, coverage, functions)
  @name = CGI::escapeHTML(name)
  @coverage = coverage
  @functions = functions
  @ignored = Xcov.ignore_handler.should_ignore_file(name)
  @displayable_coverage = self.create_displayable_coverage
  @coverage_color = self.create_coverage_color
  @id = Source.create_id(name)
  @type = Source.type(name)

  if @ignored
    UI.message "Ignoring #{name} coverage".yellow
  end
end

Instance Attribute Details

#coverageObject

Returns the value of attribute coverage.



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

def coverage
  @coverage
end

#function_templatesObject

Returns the value of attribute function_templates.



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

def function_templates
  @function_templates
end

#functionsObject

Returns the value of attribute functions.



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

def functions
  @functions
end

#ignoredObject

Returns the value of attribute ignored.



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

def ignored
  @ignored
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.



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

def type
  @type
end

Class Method Details

.map(dictionary) ⇒ Object

Class methods



46
47
48
49
50
51
52
# File 'lib/xcov/model/source.rb', line 46

def self.map (dictionary)
  name = dictionary["name"]
  coverage = dictionary["coverage"]
  functions = dictionary["functions"].map { |function| Function.map(function)}

  Source.new(name, coverage, functions)
end

.type(name) ⇒ Object



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

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



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

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

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


28
29
30
31
32
33
# File 'lib/xcov/model/source.rb', line 28

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