class MyTankInfo::TankReconciliationRecordSummary

Constants

MONTHLY_FUDGE_NUMBER
SEVEN_DAY_MULTIPLIER
TEN_DAY_MULTIPLIER

Attributes

records[R]

Public Class Methods

new(records, capacity:, reconciliation_period:) click to toggle source
# 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

Public Instance Methods

absolute_difference_volume() click to toggle source
# File lib/my_tank_info/tank_reconciliation_record_summary.rb, line 29
def absolute_difference_volume
  total_over_short.abs
end
allowable_tolerance() click to toggle source
# 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_variance() click to toggle source
# 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_multiplier() click to toggle source

10 Day Reconciliation Specific Logic

# 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?() click to toggle source
# 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_number() click to toggle source
# 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_result() click to toggle source
# 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?() click to toggle source
# 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?() click to toggle source
# File lib/my_tank_info/tank_reconciliation_record_summary.rb, line 103
def passed?
  !failed?
end
total_deliveries_volume() click to toggle source
# 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?() click to toggle source
# 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_pumped() click to toggle source

Monthly Reconciliation Specific Logic

# File lib/my_tank_info/tank_reconciliation_record_summary.rb, line 34
def total_gallons_pumped
  total_sales_volume
end
total_over_short() click to toggle source
# 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_volume() click to toggle source
# 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?() click to toggle source
# 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_number() click to toggle source
# 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_check() click to toggle source

Weekly / 7 Day Reconciliation Specific Logic

# File lib/my_tank_info/tank_reconciliation_record_summary.rb, line 65
def weekly_number_to_check
  [total_gallons_pumped, @capacity].max
end