Class: Judges::Churn

Inherits:
Object show all
Defined in:
lib/judges/churn.rb

Overview

How many facts were modified.

Author

Yegor Bugayenko (yegor256@gmail.com)

Copyright

Copyright © 2024 Yegor Bugayenko

License

MIT

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(added, removed) ⇒ Churn

Returns a new instance of Churn.



32
33
34
35
# File 'lib/judges/churn.rb', line 32

def initialize(added, removed)
  @added = added
  @removed = removed
end

Instance Attribute Details

#addedObject (readonly)

Returns the value of attribute added.



30
31
32
# File 'lib/judges/churn.rb', line 30

def added
  @added
end

#removedObject (readonly)

Returns the value of attribute removed.



30
31
32
# File 'lib/judges/churn.rb', line 30

def removed
  @removed
end

Instance Method Details

#+(other) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/judges/churn.rb', line 45

def +(other)
  if other.is_a?(Judges::Churn)
    Judges::Churn.new(@added + other.added, @removed + other.removed)
  else
    Judges::Churn.new(@added + other, @removed)
  end
end

#-(other) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/judges/churn.rb', line 53

def -(other)
  if other.is_a?(Judges::Churn)
    Judges::Churn.new(@added - other.added, @removed - other.removed)
  else
    Judges::Churn.new(@added, @removed + other)
  end
end

#to_sObject



37
38
39
# File 'lib/judges/churn.rb', line 37

def to_s
  "#{@added}/#{@removed}"
end

#zero?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/judges/churn.rb', line 41

def zero?
  @added.zero? && @removed.zero?
end