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



41
42
43
44
45
46
47
# File 'lib/factbase/churn.rb', line 41

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

#append(ins, del, add) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/factbase/churn.rb', line 33

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

#to_iObject



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

def to_i
  @inserted + @deleted + @added
end

#to_sObject



21
22
23
# File 'lib/factbase/churn.rb', line 21

def to_s
  "#{@inserted}i/#{@deleted}d/#{@added}a"
end

#zero?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/factbase/churn.rb', line 25

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