Module: Vehicles::OtherOption
- Included in:
- Vehicles
- Defined in:
- lib/vehicles/other_option.rb
Overview
The "Other / not in the list" escape hatch for make/model pickers. Mixed into
the Vehicles singleton (extend OtherOption in vehicles.rb) so Vehicles.other?
and Vehicles.other_label read as first-class module methods, and the
include_other: helpers (makes/models/*_options) can append it. Pair with
allow_other: true on the vehicle_make/vehicle_model validators. See the README
"An Other / not in the list escape hatch" section.
Constant Summary collapse
- OTHER_SLUG =
Stable, language-independent value for the escape hatch — the slug the
*_options(include_other:)helpers emit, and a valueother?always recognizes regardless of the configured display label. "other"
Instance Method Summary collapse
-
#other?(value) ⇒ Boolean
Is
valuethe "Other / not in the list" escape hatch? Forgiving: matches the configured label ("Otro") OR the canonical slug ("other"), case/diacritics- insensitively. -
#other_label ⇒ Object
The configured "Other" display label (default "Other").
Instance Method Details
#other?(value) ⇒ Boolean
Is value the "Other / not in the list" escape hatch? Forgiving: matches the
configured label ("Otro") OR the canonical slug ("other"), case/diacritics-
insensitively. nil/blank => false. Handy for hiding it from a display string
or skipping dataset lookups on it.
26 27 28 29 30 31 |
# File 'lib/vehicles/other_option.rb', line 26 def other?(value) normalized = normalize(value) return false if normalized.empty? normalized == OTHER_SLUG || normalized == normalize(other_label) end |
#other_label ⇒ Object
The configured "Other" display label (default "Other"). Use it as the picker's escape-hatch value and to recognize it on read.
18 19 20 |
# File 'lib/vehicles/other_option.rb', line 18 def other_label configuration.other_label end |