Class: MyTankInfo::TankReconciliationRecordSummary

Inherits:
Object
  • Object
show all
Defined in:
lib/my_tank_info/tank_reconciliation_record_summary.rb

Constant Summary collapse

MONTHLY_FUDGE_NUMBER =
130
TEN_DAY_MULTIPLIER =
0.0075
SEVEN_DAY_MULTIPLIER =
0.005

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(records, capacity:, reconciliation_period:) ⇒ TankReconciliationRecordSummary

Returns a new instance of TankReconciliationRecordSummary.



11
12
13
14
15
# File 'lib/my_tank_info/tank_reconciliation_record_summary.rb', line 11

def initialize(records, capacity:, reconciliation_period:)
  @records = records
  @capacity = capacity
  @reconciliation_period = reconciliation_period
end

Instance Attribute Details

#recordsObject (readonly)

Returns the value of attribute records.



5
6
7
# File 'lib/my_tank_info/tank_reconciliation_record_summary.rb', line 5

def records
  @records
end

Instance Method Details

#absolute_difference_volumeObject



29
30
31
# File 'lib/my_tank_info/tank_reconciliation_record_summary.rb', line 29

def absolute_difference_volume
  total_over_short.abs
end

#allowable_toleranceObject



56
57
58
# File 'lib/my_tank_info/tank_reconciliation_record_summary.rb', line 56

def allowable_tolerance
  (allowance_multiplier.to_f * TEN_DAY_MULTIPLIER).round(0).to_i
end

#allowable_varianceObject



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/my_tank_info/tank_reconciliation_record_summary.rb', line 77

def allowable_variance
  case @reconciliation_period
  when :monthly
    leak_check_result
  when :ten_day
    allowable_tolerance
  when :weekly
    weekly_check_number
  else
    raise ReconciliationPeriodMissingError.new
  end
end

#allowance_multiplierObject

10 Day Reconciliation Specific Logic



52
53
54
# File 'lib/my_tank_info/tank_reconciliation_record_summary.rb', line 52

def allowance_multiplier
  [@capacity, total_deliveries_volume, total_sales_volume].max
end

#failed?Boolean

Returns:

  • (Boolean)


90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/my_tank_info/tank_reconciliation_record_summary.rb', line 90

def failed?
  case @reconciliation_period
  when :monthly
    leak_check_result_unacceptable?
  when :ten_day
    variance_is_gt_allowable_tolerance?
  when :weekly
    total_gallons_larger_than_leak_check?
  else
    raise ReconciliationPeriodMissingError.new
  end
end

#leak_check_numberObject



38
39
40
41
# File 'lib/my_tank_info/tank_reconciliation_record_summary.rb', line 38

def leak_check_number
  # DROP THE LAST 2 DIGITS FROM THE PUMPED NUMBER AND ENTER ON THE LEAK CHECK
  (total_gallons_pumped.to_f / 100).round(0).to_i
end

#leak_check_resultObject



43
44
45
# File 'lib/my_tank_info/tank_reconciliation_record_summary.rb', line 43

def leak_check_result
  leak_check_number + MONTHLY_FUDGE_NUMBER
end

#leak_check_result_unacceptable?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/my_tank_info/tank_reconciliation_record_summary.rb', line 47

def leak_check_result_unacceptable?
  absolute_difference_volume > leak_check_result
end

#passed?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/my_tank_info/tank_reconciliation_record_summary.rb', line 103

def passed?
  !failed?
end

#total_deliveries_volumeObject



17
18
19
# File 'lib/my_tank_info/tank_reconciliation_record_summary.rb', line 17

def total_deliveries_volume
  @records.sum(&:deliveries_volume).round(0)
end

#total_gallons_larger_than_leak_check?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/my_tank_info/tank_reconciliation_record_summary.rb', line 73

def total_gallons_larger_than_leak_check?
  absolute_difference_volume > weekly_check_number
end

#total_gallons_pumpedObject

Monthly Reconciliation Specific Logic



34
35
36
# File 'lib/my_tank_info/tank_reconciliation_record_summary.rb', line 34

def total_gallons_pumped
  total_sales_volume
end

#total_over_shortObject



25
26
27
# File 'lib/my_tank_info/tank_reconciliation_record_summary.rb', line 25

def total_over_short
  @records.sum(&:difference_volume).round(0)
end

#total_sales_volumeObject



21
22
23
# File 'lib/my_tank_info/tank_reconciliation_record_summary.rb', line 21

def total_sales_volume
  @records.sum(&:sales_volume).round(0)
end

#variance_is_gt_allowable_tolerance?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/my_tank_info/tank_reconciliation_record_summary.rb', line 60

def variance_is_gt_allowable_tolerance?
  absolute_difference_volume > allowable_tolerance
end

#weekly_check_numberObject



69
70
71
# File 'lib/my_tank_info/tank_reconciliation_record_summary.rb', line 69

def weekly_check_number
  (weekly_number_to_check.to_f * SEVEN_DAY_MULTIPLIER).round(0).to_i
end

#weekly_number_to_checkObject

Weekly / 7 Day Reconciliation Specific Logic



65
66
67
# File 'lib/my_tank_info/tank_reconciliation_record_summary.rb', line 65

def weekly_number_to_check
  [total_gallons_pumped, @capacity].max
end