Class: GCOV::Line

Inherits:
Object
  • Object
show all
Defined in:
lib/line.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number, count, text) ⇒ Line

Returns a new instance of Line.



8
9
10
11
12
# File 'lib/line.rb', line 8

def initialize number, count, text
  @number = number
  @count = count
  @text = text
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



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

def count
  @count
end

#numberObject (readonly)

Returns the value of attribute number.



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

def number
  @number
end

#textObject (readonly)

Returns the value of attribute text.



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

def text
  @text
end

Class Method Details

.parse(line) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/line.rb', line 22

def self.parse line
  match = /^[ ]*([0-9]+|-|#####):[ ]*([0-9]+):(.*)/.match(line)
  fail "Invalid line: #{line}" unless match.to_a.count == 4
  count,number,text = match.to_a[1..3]
  number = number.to_i
  count = case count.strip
          when "-" then :none
          when "#####" then :missed
          else count.to_i
          end
  GCOV::Line.new number,count,text
end

Instance Method Details

#merge(other) ⇒ Object



47
48
49
50
51
# File 'lib/line.rb', line 47

def merge other
  result = self.dup
  result.merge! other
  result
end

#merge!(other) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/line.rb', line 35

def merge! other
  if other.count.is_a? Integer and @count.is_a? Integer
    @count += other.count
  elsif other.count.is_a? Integer
    @count = other.count
  elsif @count.is_a? Integer
    nil
  elsif other.count == :missed or @count == :missed
    @count = :missed
  end
end

#stateObject



14
15
16
17
18
19
20
# File 'lib/line.rb', line 14

def state
  case @count
  when :missed then :missed
  when :none then :none
  else :exec
  end
end