Class: Vehicles::Plates::Match
- Inherits:
-
Object
- Object
- Vehicles::Plates::Match
- Defined in:
- lib/vehicles/plates.rb
Overview
The answer to "is this a plate, and which series issues it?".
Defined Under Namespace
Classes: Hit
Instance Attribute Summary collapse
-
#canon ⇒ Object
readonly
Returns the value of attribute canon.
-
#hits ⇒ Object
readonly
Returns the value of attribute hits.
-
#input ⇒ Object
readonly
Returns the value of attribute input.
-
#jurisdiction ⇒ Object
readonly
Returns the value of attribute jurisdiction.
Instance Method Summary collapse
- #best ⇒ Object
- #exact? ⇒ Boolean
-
#formatted ⇒ Object
The serial formatted the way the best-matching series prints it on the physical plate — "1234XYZ" typed, "1234 XYZ" issued.
-
#initialize(input:, jurisdiction:, canon:, hits:) ⇒ Match
constructor
A new instance of Match.
- #series ⇒ Object
-
#strict? ⇒ Boolean
True when at least one hit is a strict-validated series — the strong signal ("the authority issues this alphabet"), vs a catch-all shape union like an export plate.
-
#suggestion ⇒ Object
Only when the user's punctuation was off: the "did you mean" string.
- #valid? ⇒ Boolean
Constructor Details
#initialize(input:, jurisdiction:, canon:, hits:) ⇒ Match
Returns a new instance of Match.
77 78 79 80 81 82 83 84 85 |
# File 'lib/vehicles/plates.rb', line 77 def initialize(input:, jurisdiction:, canon:, hits:) @input = input @jurisdiction = jurisdiction @canon = canon # Exact hits outrank lenient ones, strict-validated series outrank # recall-only catch-alls; series order (standard first) breaks ties. @hits = hits.sort_by { |h| [ h.exact? ? 0 : 1, h.series.strict? ? 0 : 1 ] }.freeze freeze end |
Instance Attribute Details
#canon ⇒ Object (readonly)
Returns the value of attribute canon.
75 76 77 |
# File 'lib/vehicles/plates.rb', line 75 def canon @canon end |
#hits ⇒ Object (readonly)
Returns the value of attribute hits.
75 76 77 |
# File 'lib/vehicles/plates.rb', line 75 def hits @hits end |
#input ⇒ Object (readonly)
Returns the value of attribute input.
75 76 77 |
# File 'lib/vehicles/plates.rb', line 75 def input @input end |
#jurisdiction ⇒ Object (readonly)
Returns the value of attribute jurisdiction.
75 76 77 |
# File 'lib/vehicles/plates.rb', line 75 def jurisdiction @jurisdiction end |
Instance Method Details
#best ⇒ Object
96 |
# File 'lib/vehicles/plates.rb', line 96 def best = hits.first&.series |
#exact? ⇒ Boolean
88 |
# File 'lib/vehicles/plates.rb', line 88 def exact? = hits.any?(&:exact?) |
#formatted ⇒ Object
The serial formatted the way the best-matching series prints it on the physical plate — "1234XYZ" typed, "1234 XYZ" issued.
100 101 102 |
# File 'lib/vehicles/plates.rb', line 100 def formatted best&.format_serial(canon) end |
#series ⇒ Object
95 |
# File 'lib/vehicles/plates.rb', line 95 def series = hits.map(&:series) |
#strict? ⇒ Boolean
True when at least one hit is a strict-validated series — the strong signal ("the authority issues this alphabet"), vs a catch-all shape union like an export plate. Prefer this for user-input validation.
93 |
# File 'lib/vehicles/plates.rb', line 93 def strict? = hits.any? { |h| h.series.strict? } |
#suggestion ⇒ Object
Only when the user's punctuation was off: the "did you mean" string.
105 106 107 |
# File 'lib/vehicles/plates.rb', line 105 def suggestion formatted if valid? && !exact? end |
#valid? ⇒ Boolean
87 |
# File 'lib/vehicles/plates.rb', line 87 def valid? = hits.any? |