Class: Support::ProjectStatsDiff::Change

Inherits:
Struct
  • Object
show all
Defined in:
lib/support/project_stats_diff.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#end_row ⇒ Object

Returns the value of attribute end_row

Returns:

  • (Object) —

    the current value of 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

Returns:

  • (Object) —

    the current value of 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

Returns:

  • (Object) —

    the current value of 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

Returns:

  • (Object) —

    the current value of 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

Returns:

  • (Object) —

    the current value of 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

Returns:

  • (Object) —

    the current value of table



23
24
25
# File 'lib/support/project_stats_diff.rb', line 23

def table
  @table
end

Instance Method Details

#changed? ⇒ Boolean

Returns:

  • (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.

Returns:

  • (Symbol) —

    :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)

Returns:

  • (Boolean)


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.

Returns:

  • (Float, nil) —

    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