Class: SCNR::Introspector::Coverage::Resource::Line

Inherits:
Object
  • Object
show all
Defined in:
lib/scnr/introspector/coverage/resource/line.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Line

Returns a new instance of Line.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :resource (Resource)
  • :number (Integer)
  • :content (String)
  • :his (nil, Integer)


33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/scnr/introspector/coverage/resource/line.rb', line 33

def initialize( options = {} )
    @resource = options[:resource]
    fail ArgumentError, 'Missing :resource' if !@resource

    @number = options[:number]
    fail ArgumentError, 'Missing :number' if !@number.is_a?( Integer )

    @content = options[:content]
    fail ArgumentError, 'Missing :content' if !@content

    @hits = options[:hits]
end

Instance Attribute Details

#contentString

Returns Line content.

Returns:

  • (String)

    Line content.



14
15
16
# File 'lib/scnr/introspector/coverage/resource/line.rb', line 14

def content
  @content
end

#hitsnil, Integer

Returns Amount of times this line was executed:

  • ‘nil` – Skipped, irrelevant code.

  • ‘0` – Missed, line wasn’t executed.

  • ‘>= 1` – Hit, line was executed.

Returns:

  • (nil, Integer)

    Amount of times this line was executed:

    • ‘nil` – Skipped, irrelevant code.

    • ‘0` – Missed, line wasn’t executed.

    • ‘>= 1` – Hit, line was executed.



26
27
28
# File 'lib/scnr/introspector/coverage/resource/line.rb', line 26

def hits
  @hits
end

#numberInteger

Returns Line number.

Returns:

  • (Integer)

    Line number.



10
11
12
# File 'lib/scnr/introspector/coverage/resource/line.rb', line 10

def number
  @number
end

#resourceResource

Returns Resource containing ‘self`.

Returns:

  • (Resource)

    Resource containing ‘self`.



18
19
20
# File 'lib/scnr/introspector/coverage/resource/line.rb', line 18

def resource
  @resource
end

Instance Method Details

#hit(count) ⇒ Object

Parameters:

  • count (Integer)

    Register ‘count` amount of hits.



76
77
78
79
80
81
# File 'lib/scnr/introspector/coverage/resource/line.rb', line 76

def hit( count )
    return if !count

    @hits ||= 0
    @hits += count
end

#hit?Bool

Returns ‘true` if the line was executed, `false` otherwise.

Returns:

  • (Bool)

    ‘true` if the line was executed, `false` otherwise.



60
61
62
# File 'lib/scnr/introspector/coverage/resource/line.rb', line 60

def hit?
    @hits.to_i > 0
end

#missed?Bool

Returns ‘true` if the line wasn’t executed, ‘false` otherwise.

Returns:

  • (Bool)

    ‘true` if the line wasn’t executed, ‘false` otherwise.



54
55
56
# File 'lib/scnr/introspector/coverage/resource/line.rb', line 54

def missed?
    @hits == 0
end

#skipped?Bool

Returns ‘true` if the line is irrelevant to the coverage, `false` otherwise.

Returns:

  • (Bool)

    ‘true` if the line is irrelevant to the coverage, `false` otherwise.



48
49
50
# File 'lib/scnr/introspector/coverage/resource/line.rb', line 48

def skipped?
    @hits.nil?
end

#stateSymbol

Returns * ‘:skipped` if #skipped?.

Returns:



68
69
70
71
72
# File 'lib/scnr/introspector/coverage/resource/line.rb', line 68

def state
    [:skipped, :missed, :hit].each do |possible_state|
        return possible_state if send("#{possible_state}?")
    end
end