Files
simple-aircraft-manager-rails/app/models/standard_inspections.rb
T
rickyandClaude Opus 5.5 61c3749793 Deferrals, expirations, standard inspections, reminders, squawk fixes
- Squawks: defer an inoperative item under 91.213(d) once each condition
  is confirmed (pilots may too); deferred items stop grounding and are
  listed for awareness. Resolving can record the fix as a logbook entry
  (43.9 fields) or link an existing one
- Expiration dates on components (ELT battery, 91.207(c)) and documents;
  new document types (registration, airworthiness certificate, insurance,
  radio license). Expired replacement-critical parts and an expired
  registration (91.203) ground; others warn; registration warns 90 days out
- Standard inspections: one click adds annual, 100-hour, 91.411, 91.413,
  ELT (91.207(d)) and VOR (91.171) checks with the right rules, skipping
  ones already tracked and linking annual to 100-hour
- Weekly Monday reminder email to owners when something needs attention;
  profile opt-out; admin "send me this week's reminder"
- README feature table updated

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 10:24:33 -05:00

54 lines
3.1 KiB
Ruby

# The recurring inspections and checks Part 91 calls for, to add to an
# aircraft in one go (Inspections → Standard inspections).
module StandardInspections
Template = Data.define(:key, :name, :who, :months, :days, :hours, :tolerance, :effect, :checked, :pattern) do
def attributes
{ name: name, recurring: true, recurring_months: months.to_i, recurring_days: days.to_i,
recurring_hours: hours.to_i, hours_tolerance: tolerance.to_i, effect: effect }
end
end
TEMPLATES = [
Template.new(key: "annual", name: "Annual inspection (91.409(a))", who: "Every aircraft",
months: 12, days: nil, hours: nil, tolerance: nil, effect: "grounds", checked: true, pattern: /annual/i),
Template.new(key: "hundred", name: "100-hour inspection (91.409(b))", who: "Carrying anyone for hire, or flight instruction for hire",
months: nil, days: nil, hours: 100, tolerance: 10, effect: "grounds", checked: false, pattern: /100[- ]?h(ou)?r/i),
Template.new(key: "transponder", name: "Transponder check (91.413)", who: "Aircraft with a transponder",
months: 24, days: nil, hours: nil, tolerance: nil, effect: "no_transponder", checked: true, pattern: /transponder|91\.413/i),
Template.new(key: "pitot_static", name: "Altimeter and static system check (91.411)", who: "Flying IFR in controlled airspace",
months: 24, days: nil, hours: nil, tolerance: nil, effect: "no_ifr", checked: false, pattern: /pitot|static|altimeter|91\.411/i),
Template.new(key: "elt", name: "ELT inspection (91.207(d))", who: "Aircraft required to carry an ELT",
months: 12, days: nil, hours: nil, tolerance: nil, effect: "grounds", checked: true, pattern: /\belt\b|91\.207/i),
Template.new(key: "vor", name: "VOR check (91.171)", who: "Flying IFR using VORs; the pilot may do and log it",
months: nil, days: 30, hours: nil, tolerance: nil, effect: "no_ifr", checked: false, pattern: /\bvor\b|91\.171/i)
].freeze
module_function
def find(key) = TEMPLATES.find { _1.key == key }
# The aircraft's existing inspection type a template matches, if any.
def existing_for(template, aircraft)
aircraft.applicable_inspection_types.find { _1.name.match?(template.pattern) }
end
# Adds the chosen templates the aircraft doesn't already track. Returns the
# inspection types added.
def add!(aircraft, keys)
added = {}
InspectionType.transaction do
Array(keys).filter_map { find(_1.to_s) }.each do |t|
next if existing_for(t, aircraft)
type = InspectionType.find_by(name: t.name) || InspectionType.create!(t.attributes)
type.aircraft << aircraft unless type.aircraft.include?(aircraft)
added[t.key] = type
end
# An annual also counts as the 100-hour (91.409(b)).
annual = added["annual"] || (find("annual") && existing_for(find("annual"), aircraft))
hundred = added["hundred"] || existing_for(find("hundred"), aircraft)
annual.update!(satisfies: hundred) if annual && hundred && annual.satisfies_id.nil? && (added["annual"] || added["hundred"])
end
added.values
end
end