Class: Factbase::Churn

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

Overview

A churn.

Author

Yegor Bugayenko ([email protected])

Copyright

Copyright © 2024-2025 Yegor Bugayenko

License

MIT

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ins = 0, del = 0, add = 0) ⇒ Churn

Returns a new instance of Churn.



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

def initialize(ins = 0, del = 0, add = 0)
  @mutex = Mutex.new
  @inserted = ins
  @deleted = del
  @added = add
end

Instance Attribute Details

#addedObject (readonly)

Returns the value of attribute added.



12
13
14
# File 'lib/factbase/churn.rb', line 12

def added
  @added
end

#deletedObject (readonly)

Returns the value of attribute deleted.



12
13
14
# File 'lib/factbase/churn.rb', line 12

def deleted
  @deleted
end

#insertedObject (readonly)

Returns the value of attribute inserted.



12
13
14
# File 'lib/factbase/churn.rb', line 12

def inserted
  @inserted
end

Instance Method Details

#+(other) ⇒ Object



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

def +(other)
  Factbase::Churn.new(
    @inserted + other.inserted,
    @deleted + other.deleted,
    @added + other.added
  )
end

#append(ins, del, add) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/factbase/churn.rb', line 37

def append(ins, del, add)
  @mutex.synchronize do
    @inserted += ins
    @deleted += del
    @added += add
  end
end

#to_iObject



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

def to_i
  @inserted + @deleted + @added
end

#to_sObject



21
22
23
24
25
26
27
# File 'lib/factbase/churn.rb', line 21

def to_s
  if zero?
    'nothing'
  else
    "#{@inserted}i/#{@deleted}d/#{@added}a"
  end
end

#zero?Boolean

Returns:



29
30
31
# File 'lib/factbase/churn.rb', line 29

def zero?
  @inserted.zero? && @deleted.zero? && @added.zero?
end