Class: AtlasEngine::AddressNumber

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
app/models/atlas_engine/address_number.rb

Constant Summary collapse

NUMBERS =
/\d+/
NUMBERS_AND_NON_NUMBERS =
%r{([A-Za-z]+|\d+\s+\d+/\d+|\d+/\d+|\d+|-)}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value:) ⇒ AddressNumber

Returns a new instance of AddressNumber.



15
16
17
# File 'app/models/atlas_engine/address_number.rb', line 15

def initialize(value:)
  @raw = value
end

Instance Attribute Details

#rawObject (readonly)

Returns the value of attribute raw.



9
10
11
# File 'app/models/atlas_engine/address_number.rb', line 9

def raw
  @raw
end

Instance Method Details

#segmentsObject



32
33
34
# File 'app/models/atlas_engine/address_number.rb', line 32

def segments
  Array(@raw.scan(NUMBERS_AND_NON_NUMBERS).flatten)
end

#to_iObject



20
21
22
23
# File 'app/models/atlas_engine/address_number.rb', line 20

def to_i
  numbers = @raw.scan(NUMBERS).flatten
  numbers.length == 1 ? numbers[0].to_i : nil
end

#to_rObject



26
27
28
29
# File 'app/models/atlas_engine/address_number.rb', line 26

def to_r
  fractions = @raw.scan(NUMBERS_AND_NON_NUMBERS).flatten
  fractions[0].to_s.split.sum(&:to_r)
end