Class: AtlasEngine::AddressValidation::Candidate
- Inherits:
-
Object
- Object
- AtlasEngine::AddressValidation::Candidate
- Extended by:
- T::Sig
- Defined in:
- app/models/atlas_engine/address_validation/candidate.rb
Defined Under Namespace
Classes: Component
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#index ⇒ Object
readonly
Returns the value of attribute index.
-
#position ⇒ Object
Returns the value of attribute position.
Class Method Summary collapse
Instance Method Summary collapse
- #component(name) ⇒ Object
- #components(*names) ⇒ Object
- #describes_general_delivery? ⇒ Boolean
- #describes_po_box? ⇒ Boolean
-
#initialize(id:, source:, position: 0, index: nil) ⇒ Candidate
constructor
A new instance of Candidate.
- #serialize ⇒ Object
Constructor Details
#initialize(id:, source:, position: 0, index: nil) ⇒ Candidate
Returns a new instance of Candidate.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'app/models/atlas_engine/address_validation/candidate.rb', line 12 def initialize(id:, source:, position: 0, index: nil) components_hash = Hash.new { |hash, key| hash[key] = Component.new(key, nil) } @components = source.each_with_object(components_hash) do |(key, value), hash| hash[key.to_sym] = Component.new(key.to_sym, value) end @id = id @components[:id] = Component.new(:id, id) @index = index end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
8 9 10 |
# File 'app/models/atlas_engine/address_validation/candidate.rb', line 8 def id @id end |
#index ⇒ Object (readonly)
Returns the value of attribute index.
8 9 10 |
# File 'app/models/atlas_engine/address_validation/candidate.rb', line 8 def index @index end |
#position ⇒ Object
Returns the value of attribute position.
9 10 11 |
# File 'app/models/atlas_engine/address_validation/candidate.rb', line 9 def position @position end |
Class Method Details
.from(hit) ⇒ Object
58 59 60 61 62 63 64 |
# File 'app/models/atlas_engine/address_validation/candidate.rb', line 58 def from(hit) id = hit.dig("_id") source = hit.dig("_source") source["city"] = source["city_aliases"].map(&:values).flatten if source["city_aliases"] index = hit.dig("_index") new(id: id, source: source, index: index) end |
Instance Method Details
#component(name) ⇒ Object
25 26 27 |
# File 'app/models/atlas_engine/address_validation/candidate.rb', line 25 def component(name) @components[name] end |
#components(*names) ⇒ Object
30 31 32 33 34 35 36 |
# File 'app/models/atlas_engine/address_validation/candidate.rb', line 30 def components(*names) return @components.reject { |_, component| component.value.nil? } if names.empty? names.index_with do |name| component(name) end end |
#describes_general_delivery? ⇒ Boolean
50 51 52 |
# File 'app/models/atlas_engine/address_validation/candidate.rb', line 50 def describes_general_delivery? component(:street)&.value&.casecmp("general delivery") == 0 end |
#describes_po_box? ⇒ Boolean
45 46 47 |
# File 'app/models/atlas_engine/address_validation/candidate.rb', line 45 def describes_po_box? component(:street)&.value&.casecmp("po box") == 0 end |
#serialize ⇒ Object
39 40 41 42 |
# File 'app/models/atlas_engine/address_validation/candidate.rb', line 39 def serialize components(:locale, :province_code, :region2, :region3, :region4, :zip, :city, :suburb, :street) .values.map(&:serialize).join(",") end |