Class: AtlasEngine::AddressNumber
- Inherits:
-
Object
- Object
- AtlasEngine::AddressNumber
- 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
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
Instance Method Summary collapse
-
#initialize(value:) ⇒ AddressNumber
constructor
A new instance of AddressNumber.
- #segments ⇒ Object
- #to_i ⇒ Object
- #to_r ⇒ Object
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
#raw ⇒ Object (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
#segments ⇒ Object
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_i ⇒ Object
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_r ⇒ Object
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 |