Class: Factbase::Churn
- Inherits:
-
Object
- Object
- Factbase::Churn
- Defined in:
- lib/factbase/churn.rb
Overview
A churn.
- Author
-
Yegor Bugayenko (yegor256@gmail.com)
- Copyright
-
Copyright © 2024-2026 Yegor Bugayenko
- License
-
MIT
Instance Attribute Summary collapse
-
#added ⇒ Object
readonly
Returns the value of attribute added.
-
#deleted ⇒ Object
readonly
Returns the value of attribute deleted.
-
#inserted ⇒ Object
readonly
Returns the value of attribute inserted.
Instance Method Summary collapse
- #+(other) ⇒ Object
- #append(ins, del, add) ⇒ Object
-
#initialize(ins = 0, del = 0, add = 0) ⇒ Churn
constructor
A new instance of Churn.
- #to_i ⇒ Object
- #to_s ⇒ Object
- #zero? ⇒ Boolean
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
#added ⇒ Object (readonly)
Returns the value of attribute added.
12 13 14 |
# File 'lib/factbase/churn.rb', line 12 def added @added end |
#deleted ⇒ Object (readonly)
Returns the value of attribute deleted.
12 13 14 |
# File 'lib/factbase/churn.rb', line 12 def deleted @deleted end |
#inserted ⇒ Object (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 |
# 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_i ⇒ Object
33 34 35 |
# File 'lib/factbase/churn.rb', line 33 def to_i inserted + deleted + added end |
#to_s ⇒ Object
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
29 30 31 |
# File 'lib/factbase/churn.rb', line 29 def zero? inserted.zero? && deleted.zero? && added.zero? end |