Class: Edoxen::VenueValidator
- Inherits:
-
Object
- Object
- Edoxen::VenueValidator
- Defined in:
- lib/edoxen/venue_validator.rb,
sig/edoxen.rbs
Overview
VenueValidator — validates Venue instances using the unlocodes
and iata gems. Returns a list of errors; empty list means valid.
For a Venue with kind: "physical", validates that any populated
unlocode and iata_code exist in the canonical registries.
valid? and validate are pure queries — they do not mutate the
venue. Callers who want city/country_code back-filled from the
UN/LOCODE registry use populate_from_registry!, a separate,
explicitly-mutating method.
Instance Attribute Summary collapse
-
#errors ⇒ Array[String]
readonly
Returns the value of attribute errors.
-
#venue ⇒ Venue
readonly
Returns the value of attribute venue.
Instance Method Summary collapse
-
#initialize(venue) ⇒ VenueValidator
constructor
A new instance of VenueValidator.
-
#populate_from_registry! ⇒ Object
Mutator: back-fill
venue.cityandvenue.country_codefrom the UN/LOCODE entry. -
#valid? ⇒ Boolean
Pure boolean wrapper around
validate. -
#validate ⇒ Array[String]
Pure query.
Constructor Details
#initialize(venue) ⇒ VenueValidator
Returns a new instance of VenueValidator.
17 18 19 20 |
# File 'lib/edoxen/venue_validator.rb', line 17 def initialize(venue) @venue = venue @errors = [] end |
Instance Attribute Details
#errors ⇒ Array[String] (readonly)
Returns the value of attribute errors.
15 16 17 |
# File 'lib/edoxen/venue_validator.rb', line 15 def errors @errors end |
#venue ⇒ Venue (readonly)
Returns the value of attribute venue.
15 16 17 |
# File 'lib/edoxen/venue_validator.rb', line 15 def venue @venue end |
Instance Method Details
#populate_from_registry! ⇒ Object
Mutator: back-fill venue.city and venue.country_code from the
UN/LOCODE entry. Raises KeyError when the unlocode is unknown
or unset, so callers do not silently leave the venue untouched.
Returns the venue (so callers can chain).
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/edoxen/venue_validator.rb', line 41 def populate_from_registry! raise KeyError, "populate_from_registry! requires kind: physical" unless venue.physical? raise KeyError, "populate_from_registry! requires unlocode" if venue.unlocode.nil? || venue.unlocode.to_s.empty? entry = Edoxen::ReferenceData.find_unlocode(venue.unlocode) raise KeyError, "Unknown UN/LOCODE: #{venue.unlocode}" if entry.nil? venue.city ||= entry.name venue.country_code ||= entry.country venue end |
#valid? ⇒ Boolean
Pure boolean wrapper around validate.
31 32 33 34 |
# File 'lib/edoxen/venue_validator.rb', line 31 def valid? validate errors.empty? end |
#validate ⇒ Array[String]
Pure query. Populates errors and returns it; does not modify
the venue.
24 25 26 27 28 |
# File 'lib/edoxen/venue_validator.rb', line 24 def validate errors.clear validate_physical if venue.physical? errors end |