Class: Support::ProjectStatsDiff::Change
- Inherits:
-
Struct
- Object
- Struct
- Support::ProjectStatsDiff::Change
- Defined in:
- lib/support/project_stats_diff.rb
Instance Attribute Summary collapse
-
#end_row ⇒ Object
Returns the value of attribute end_row.
-
#model ⇒ Object
Returns the value of attribute model.
-
#project_id ⇒ Object
Returns the value of attribute project_id.
-
#project_name ⇒ Object
Returns the value of attribute project_name.
-
#start_row ⇒ Object
Returns the value of attribute start_row.
-
#table ⇒ Object
Returns the value of attribute table.
Instance Method Summary collapse
- #changed? ⇒ Boolean
- #delta ⇒ Object
- #end_count ⇒ Object
-
#kind ⇒ Symbol
:emptied, :new, :count or :same_count.
- #later?(start_time, end_time) ⇒ Boolean private
-
#percent ⇒ Float?
Nil when the start count is 0.
- #signals ⇒ Object
- #start_count ⇒ Object
- #time(row, column) ⇒ Object private
- #value(row, column) ⇒ Object private
Instance Attribute Details
#end_row ⇒ Object
Returns the value of attribute end_row
23 24 25 |
# File 'lib/support/project_stats_diff.rb', line 23 def end_row @end_row end |
#model ⇒ Object
Returns the value of attribute model
23 24 25 |
# File 'lib/support/project_stats_diff.rb', line 23 def model @model end |
#project_id ⇒ Object
Returns the value of attribute project_id
23 24 25 |
# File 'lib/support/project_stats_diff.rb', line 23 def project_id @project_id end |
#project_name ⇒ Object
Returns the value of attribute project_name
23 24 25 |
# File 'lib/support/project_stats_diff.rb', line 23 def project_name @project_name end |
#start_row ⇒ Object
Returns the value of attribute start_row
23 24 25 |
# File 'lib/support/project_stats_diff.rb', line 23 def start_row @start_row end |
#table ⇒ Object
Returns the value of attribute table
23 24 25 |
# File 'lib/support/project_stats_diff.rb', line 23 def table @table end |
Instance Method Details
#changed? ⇒ Boolean
64 65 66 |
# File 'lib/support/project_stats_diff.rb', line 64 def changed? delta != 0 || signals.any? end |
#delta ⇒ Object
32 33 34 |
# File 'lib/support/project_stats_diff.rb', line 32 def delta end_count - start_count end |
#end_count ⇒ Object
28 29 30 |
# File 'lib/support/project_stats_diff.rb', line 28 def end_count end_row ? end_row['count'].to_i : 0 end |
#kind ⇒ Symbol
Returns :emptied, :new, :count or :same_count.
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/support/project_stats_diff.rb', line 43 def kind if start_count > 0 && end_count.zero? :emptied elsif start_count.zero? && end_count > 0 :new elsif delta != 0 :count else :same_count end end |
#later?(start_time, end_time) ⇒ Boolean (private)
79 80 81 |
# File 'lib/support/project_stats_diff.rb', line 79 def later?(start_time, end_time) !end_time.nil? && (start_time.nil? || end_time > start_time) end |
#percent ⇒ Float?
Returns nil when the start count is 0.
37 38 39 40 |
# File 'lib/support/project_stats_diff.rb', line 37 def percent return nil if start_count.zero? (delta * 100.0 / start_count).round(1) end |
#signals ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/support/project_stats_diff.rb', line 55 def signals inserted = value(end_row, 'max_id').to_i > value(start_row, 'max_id').to_i s = [] s << :inserted if inserted s << :deleted if delta < 0 || (inserted && delta <= 0 && end_count > 0) s << :updated if !inserted && later?(time(start_row, 'max_updated_at'), time(end_row, 'max_updated_at')) s end |
#start_count ⇒ Object
24 25 26 |
# File 'lib/support/project_stats_diff.rb', line 24 def start_count start_row ? start_row['count'].to_i : 0 end |
#time(row, column) ⇒ Object (private)
74 75 76 77 |
# File 'lib/support/project_stats_diff.rb', line 74 def time(row, column) v = value(row, column) v.nil? || v.empty? ? nil : Time.parse(v) end |
#value(row, column) ⇒ Object (private)
70 71 72 |
# File 'lib/support/project_stats_diff.rb', line 70 def value(row, column) row && row[column].to_s end |