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
    fail '@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)


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

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)


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

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)


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

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

#present?Boolean

Returns:

  • (Boolean)


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

def present?
  @before && @after
end

#removed?Boolean

Returns:

  • (Boolean)


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

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

#scoresObject



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

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

#unchanged?Boolean

Returns:

  • (Boolean)


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

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