Class: Inch::API::Compare::CodeObjects

Inherits:
Object
  • Object
show all
Defined in:
lib/inch/api/compare/code_objects.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object1, object2) ⇒ CodeObjects

Returns a new instance of CodeObjects.



7
8
9
10
11
12
# File 'lib/inch/api/compare/code_objects.rb', line 7

def initialize(object1, object2)
  @before, @after = object1, object2
  if @before.object_id == @after.object_id
    raise "@before and @after are identical ruby objects. this is bad."
  end
end

Instance Attribute Details

#afterObject (readonly)

Returns the value of attribute after.



5
6
7
# File 'lib/inch/api/compare/code_objects.rb', line 5

def after
  @after
end

#beforeObject (readonly)

Returns the value of attribute before.



5
6
7
# File 'lib/inch/api/compare/code_objects.rb', line 5

def before
  @before
end

Instance Method Details

#added?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/inch/api/compare/code_objects.rb', line 27

def added?
  @before.nil? && !@after.nil?
end

#changed?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/inch/api/compare/code_objects.rb', line 14

def changed?
  present? && !unchanged?
end

#degraded?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/inch/api/compare/code_objects.rb', line 31

def degraded?
  changed? && @before.score > @after.score
end

#fullnameObject



18
19
20
# File 'lib/inch/api/compare/code_objects.rb', line 18

def fullname
  (@before || @after).fullname
end

#gradeObject



22
23
24
# File 'lib/inch/api/compare/code_objects.rb', line 22

def grade
  @after.grade
end

#improved?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/inch/api/compare/code_objects.rb', line 35

def improved?
  changed? && @before.score < @after.score
end

#present?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/inch/api/compare/code_objects.rb', line 39

def present?
  @before && @after
end

#removed?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/inch/api/compare/code_objects.rb', line 43

def removed?
  !@before.nil? && @after.nil?
end

#scoresObject



51
52
53
# File 'lib/inch/api/compare/code_objects.rb', line 51

def scores
  [@before.score, @after.score]
end

#unchanged?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/inch/api/compare/code_objects.rb', line 47

def unchanged?
  present? && @before.score == @after.score
end