Class: Factbase::Churn
- Inherits:
-
Object
- Object
- Factbase::Churn
- 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
-
#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
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_i ⇒ Object
29 30 31 |
# File 'lib/factbase/churn.rb', line 29 def to_i @inserted + @deleted + @added end |
#to_s ⇒ Object
21 22 23 |
# File 'lib/factbase/churn.rb', line 21 def to_s "#{@inserted}i/#{@deleted}d/#{@added}a" end |
#zero? ⇒ Boolean
25 26 27 |
# File 'lib/factbase/churn.rb', line 25 def zero? @inserted.zero? && @deleted.zero? && @added.zero? end |