Class: AddressValidation::Result
- Inherits:
-
Data
- Object
- Data
- AddressValidation::Result
- Defined in:
- app/services/address_validation/result.rb
Overview
Outcome of an address-verification request, normalized across providers.
Instance Attribute Summary collapse
-
#candidates ⇒ Array<AddressValidation::Candidate>
readonly
Suggested corrections.
-
#message ⇒ String?
readonly
Provider status message.
-
#provider ⇒ Symbol
readonly
Which provider produced this result.
-
#status ⇒ Symbol
readonly
One of: - +:verified+ — a single confident canonical match - +:ambiguous+ — multiple plausible candidates - +:unverified+ — provider rejected the address - +:indeterminate+ — provider couldn't decide / declined to validate - +:error+ — the provider call failed.
Instance Method Summary collapse
- #ambiguous? ⇒ Boolean
-
#best ⇒ AddressValidation::Candidate?
The top candidate.
- #initialize(status:, candidates: [], provider: nil, message: nil) ⇒ void constructor
-
#verified? ⇒ Boolean
True when exactly one confident correction is available.
Constructor Details
#initialize(status:, candidates: [], provider: nil, message: nil) ⇒ void
27 28 29 |
# File 'app/services/address_validation/result.rb', line 27 def initialize(status:, candidates: [], provider: nil, message: nil) super(status: status, candidates: candidates.freeze, provider: provider, message: ) end |
Instance Attribute Details
#candidates ⇒ Array<AddressValidation::Candidate> (readonly)
Returns suggested corrections.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/services/address_validation/result.rb', line 21 Result = Data.define(:status, :candidates, :provider, :message) do # @param status [Symbol] one of :verified, :ambiguous, :unverified, :indeterminate, :error # @param candidates [Array<AddressValidation::Candidate>] suggested corrections # @param provider [Symbol, nil] which provider produced this result # @param message [String, nil] provider status message # @return [void] def initialize(status:, candidates: [], provider: nil, message: nil) super(status: status, candidates: candidates.freeze, provider: provider, message: ) end # @return [Boolean] true when exactly one confident correction is available. def verified? = status == :verified && candidates.one? # @return [Boolean] def ambiguous? = status == :ambiguous # @return [AddressValidation::Candidate, nil] the top candidate. def best = candidates.first end |
#message ⇒ String? (readonly)
Returns provider status message.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/services/address_validation/result.rb', line 21 Result = Data.define(:status, :candidates, :provider, :message) do # @param status [Symbol] one of :verified, :ambiguous, :unverified, :indeterminate, :error # @param candidates [Array<AddressValidation::Candidate>] suggested corrections # @param provider [Symbol, nil] which provider produced this result # @param message [String, nil] provider status message # @return [void] def initialize(status:, candidates: [], provider: nil, message: nil) super(status: status, candidates: candidates.freeze, provider: provider, message: ) end # @return [Boolean] true when exactly one confident correction is available. def verified? = status == :verified && candidates.one? # @return [Boolean] def ambiguous? = status == :ambiguous # @return [AddressValidation::Candidate, nil] the top candidate. def best = candidates.first end |
#provider ⇒ Symbol (readonly)
Returns which provider produced this result.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/services/address_validation/result.rb', line 21 Result = Data.define(:status, :candidates, :provider, :message) do # @param status [Symbol] one of :verified, :ambiguous, :unverified, :indeterminate, :error # @param candidates [Array<AddressValidation::Candidate>] suggested corrections # @param provider [Symbol, nil] which provider produced this result # @param message [String, nil] provider status message # @return [void] def initialize(status:, candidates: [], provider: nil, message: nil) super(status: status, candidates: candidates.freeze, provider: provider, message: ) end # @return [Boolean] true when exactly one confident correction is available. def verified? = status == :verified && candidates.one? # @return [Boolean] def ambiguous? = status == :ambiguous # @return [AddressValidation::Candidate, nil] the top candidate. def best = candidates.first end |
#status ⇒ Symbol (readonly)
Returns one of:
- +:verified+ — a single confident canonical match
- +:ambiguous+ — multiple plausible candidates
- +:unverified+ — provider rejected the address
- +:indeterminate+ — provider couldn't decide / declined to validate
- +:error+ — the provider call failed.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'app/services/address_validation/result.rb', line 21 Result = Data.define(:status, :candidates, :provider, :message) do # @param status [Symbol] one of :verified, :ambiguous, :unverified, :indeterminate, :error # @param candidates [Array<AddressValidation::Candidate>] suggested corrections # @param provider [Symbol, nil] which provider produced this result # @param message [String, nil] provider status message # @return [void] def initialize(status:, candidates: [], provider: nil, message: nil) super(status: status, candidates: candidates.freeze, provider: provider, message: ) end # @return [Boolean] true when exactly one confident correction is available. def verified? = status == :verified && candidates.one? # @return [Boolean] def ambiguous? = status == :ambiguous # @return [AddressValidation::Candidate, nil] the top candidate. def best = candidates.first end |
Instance Method Details
#ambiguous? ⇒ Boolean
35 |
# File 'app/services/address_validation/result.rb', line 35 def ambiguous? = status == :ambiguous |
#best ⇒ AddressValidation::Candidate?
Returns the top candidate.
38 |
# File 'app/services/address_validation/result.rb', line 38 def best = candidates.first |
#verified? ⇒ Boolean
Returns true when exactly one confident correction is available.
32 |
# File 'app/services/address_validation/result.rb', line 32 def verified? = status == :verified && candidates.one? |