Class: AtlasEngine::AddressValidation::Validators::FullAddress::NumberComparison

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
app/models/atlas_engine/address_validation/validators/full_address/number_comparison.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(numbers: [], candidate_ranges: []) ⇒ NumberComparison

Returns a new instance of NumberComparison.



13
14
15
16
# File 'app/models/atlas_engine/address_validation/validators/full_address/number_comparison.rb', line 13

def initialize(numbers: [], candidate_ranges: [])
  @numbers = numbers
  @candidate_ranges = candidate_ranges
end

Instance Attribute Details

#candidate_rangesObject (readonly)

Returns the value of attribute candidate_ranges.



11
12
13
# File 'app/models/atlas_engine/address_validation/validators/full_address/number_comparison.rb', line 11

def candidate_ranges
  @candidate_ranges
end

#numbersObject (readonly)

Returns the value of attribute numbers.



11
12
13
# File 'app/models/atlas_engine/address_validation/validators/full_address/number_comparison.rb', line 11

def numbers
  @numbers
end

Instance Method Details

#match?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
26
# File 'app/models/atlas_engine/address_validation/validators/full_address/number_comparison.rb', line 18

def match?
  return true if candidate_ranges.blank? && numbers.present?

  numbers.compact.any? do |number|
    candidate_ranges.any? do |candidate_range|
      candidate_range.include?(number)
    end
  end
end