Class: Judges::Churn

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

Overview

How many facts were modified.

Author

Yegor Bugayenko ([email protected])

Copyright

Copyright © 2024 Yegor Bugayenko

License

MIT

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(added, removed, errors = []) ⇒ Churn

Returns a new instance of Churn.



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

def initialize(added, removed, errors = [])
  @added = added
  @removed = removed
  @errors = errors
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

#errorsObject (readonly)

Returns the value of attribute errors.



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

def errors
  @errors
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



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

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

#-(other) ⇒ Object



59
60
61
62
63
64
65
# File 'lib/judges/churn.rb', line 59

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

#<<(error) ⇒ Object



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

def <<(error)
  @errors << error
  nil
end

#to_sObject



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

def to_s
  "#{@added}/#{@removed}#{@errors.empty? ? '' : "/#{@errors.size}"}"
end

#zero?Boolean

Returns:

  • (Boolean)


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

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