mirror of
https://github.com/rickbarrette/simple-aircraft-manager-rails.git
synced 2026-11-17 15:50:36 -05:00
- Views use lazy t(".key") lookups; sentences with values or links stay
whole (interpolation, _html keys); counts use one/other plurals
- Stored-value labels (statuses, types, priorities...) are LabelSets read
from labels: in the current locale; field names and validation messages
under activerecord:; flash and activity text under flash:
- Services, models, helpers, mailer subjects, the logbook PDF, procedures
templates, records package README and transcription warnings localized;
the PDF reuses LogbookEntry#certification_statement instead of a copy
- Scripts read js: strings from a JSON tag via app/javascript/i18n.js
- Dates through I18n.l (app, weekday, month_year, long formats); html lang
follows the locale
- APP_LOCALE picks the language (falls back to English); missing
translations raise in development and tests
- README: Translating section and APP_LOCALE
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
26 lines
1.2 KiB
Ruby
26 lines
1.2 KiB
Ruby
# A user's FAA certificate (A&P, IA, pilot…), used to sign logbook entries.
|
|
# Some expire (an Inspection Authorization lapses on March 31 of each
|
|
# odd-numbered year unless renewed, 14 CFR 65.92).
|
|
class UserCertificate < ApplicationRecord
|
|
KINDS = LogbookEntry::CERTIFICATE_TYPES
|
|
MECHANIC_KINDS = %w[AP IA A P REPAIR_STATION REPAIRMAN].freeze
|
|
SHORT_LABELS = LabelSet.new("user_certificate.short_labels", %w[AP IA A P REPAIR_STATION REPAIRMAN PILOT OTHER])
|
|
EXPIRY_WARNING_DAYS = 60
|
|
|
|
belongs_to :user
|
|
|
|
normalizes :number, with: ->(n) { n.strip }
|
|
validates :kind, inclusion: { in: KINDS.keys }
|
|
validates :number, presence: true, length: { maximum: 40 }
|
|
|
|
scope :ordered, -> { order(Arel.sql("CASE kind WHEN 'IA' THEN 0 WHEN 'AP' THEN 1 ELSE 2 END"), :created_at) }
|
|
# Expiring soon, or lapsed in the last month (so it isn't mentioned forever).
|
|
scope :expiring, ->(within = EXPIRY_WARNING_DAYS.days) { where(expires_on: (Date.current - 30)..(Date.current + within)) }
|
|
|
|
def kind_label = KINDS[kind]
|
|
def short_label = SHORT_LABELS[kind]
|
|
def mechanic? = MECHANIC_KINDS.include?(kind)
|
|
def expired?(today = Date.current) = expires_on.present? && today > expires_on
|
|
def to_s = "#{kind_label} #{number}"
|
|
end
|