Module: Paf::CoreExt::String

Defined in:
lib/paf/core_ext/string.rb

Overview

Extend the core String class with PAF specific processing

Instance Method Summary collapse

Instance Method Details

#but_last_wordObject



36
37
38
# File 'lib/paf/core_ext/string.rb', line 36

def but_last_word
  self[0...rindex(' ')]
end

#exception?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/paf/core_ext/string.rb', line 17

def exception?
  !/^(.|[\d][[:alpha:]]|[\d].*?[\d][[:alpha:]]?)$/.match(self).nil?
end

#exception_i?Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/paf/core_ext/string.rb', line 5

def exception_i?
  !/\A\d.*\d\z/.match(self).nil?
end

#exception_ii?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/paf/core_ext/string.rb', line 9

def exception_ii?
  !/\A\d[A-Za-z]\z|\A\d.*\d[A-Za-z]\z/.match(self).nil?
end

#exception_iii?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/paf/core_ext/string.rb', line 13

def exception_iii?
  !/\A\S\z/.match(self).nil?
end

#known_building_type?Boolean

Returns:

  • (Boolean)


40
41
42
43
44
45
46
# File 'lib/paf/core_ext/string.rb', line 40

def known_building_type?
  [
    'BACK OF', 'BLOCK', 'BLOCKS', 'BUILDING', 'MAISONETTE', 'MAISONETTES', 'REAR OF',
    'SHOP', 'SHOPS', 'STALL', 'STALLS', 'SUITE', 'SUITES', 'UNIT', 'UNITS',
    'FLAT', 'FLATS', 'PO BOX'
  ].include?(self)
end

#known_split_building_type?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/paf/core_ext/string.rb', line 48

def known_split_building_type?
  ['UNIT'].include?(self)
end

#last_wordObject



32
33
34
# File 'lib/paf/core_ext/string.rb', line 32

def last_word
  split.last
end

#penultimate_wordObject



28
29
30
# File 'lib/paf/core_ext/string.rb', line 28

def penultimate_word
  but_last_word.last_word
end

#split_exception?Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
# File 'lib/paf/core_ext/string.rb', line 21

def split_exception?
  (last_word.exception_i? || last_word.exception_ii?) &&
    /^\d+$/.match(last_word).nil? &&
    !but_last_word.known_building_type? &&
    !penultimate_word.known_split_building_type?
end