Class: Ubi::Memoria::Address
Overview
An address in this world
Ignorace < Bliss
Yeah, this needs lots of work. Geonames in memory country with zip/cities and regions, and some neural thing. And geocode to use openstreet or else.
Don’t hesitate to improve your AI skills here.
Constant Summary collapse
- DIVIDERS =
%r{[,\-\|/]}
- SPLIT =
/(?<=\D)#{DIVIDERS}|#{DIVIDERS}(?=\D)/
- REGEXES =
{ br: { prefix: %w( r rua av avenida pc pca praça pc pca praca tv travessa est estrada rod rodovia ), number: %w( n no nº num numero km ), ext: %w( comp obs ap apto apart apartamento andar ), zip: /\d{5}\s?[-]\s?\d{3}/ }, us: { prefix: %w( st street av avenue road ), zip: /\d{5}/ } }
Instance Attribute Summary collapse
-
#city ⇒ Object
Returns the value of attribute city.
-
#clean ⇒ Object
Returns the value of attribute clean.
-
#extra ⇒ Object
Returns the value of attribute extra.
-
#name ⇒ Object
Returns the value of attribute name.
-
#nation ⇒ Object
Returns the value of attribute nation.
-
#number ⇒ Object
Returns the value of attribute number.
-
#parts ⇒ Object
Returns the value of attribute parts.
-
#place ⇒ Object
Returns the value of attribute place.
-
#region ⇒ Object
Returns the value of attribute region.
-
#words ⇒ Object
Returns the value of attribute words.
-
#zip ⇒ Object
Returns the value of attribute zip.
Attributes inherited from Base
Class Method Summary collapse
- .formats ⇒ Object
- .plural ⇒ Object
- .regex(hint) ⇒ Object
-
.sanitize(txt) ⇒ Object
Sanitizing.
- .zip_format ⇒ Object
Instance Method Summary collapse
- #fetch_possible ⇒ Object
- #format(location = :br) ⇒ Object
- #parse_zip ⇒ Object
-
#parser ⇒ Object
Init, remove non word chars.
Methods inherited from Base
#==, extract_text, inherited, #initialize, key, name, parse, parse!, #to_s
Constructor Details
This class inherits a constructor from Ubi::Memoria::Base
Instance Attribute Details
#city ⇒ Object
Returns the value of attribute city.
29 30 31 |
# File 'lib/ubi/memorias/address.rb', line 29 def city @city end |
#clean ⇒ Object
Returns the value of attribute clean.
29 30 31 |
# File 'lib/ubi/memorias/address.rb', line 29 def clean @clean end |
#extra ⇒ Object
Returns the value of attribute extra.
29 30 31 |
# File 'lib/ubi/memorias/address.rb', line 29 def extra @extra end |
#name ⇒ Object
Returns the value of attribute name.
29 30 31 |
# File 'lib/ubi/memorias/address.rb', line 29 def name @name end |
#nation ⇒ Object
Returns the value of attribute nation.
29 30 31 |
# File 'lib/ubi/memorias/address.rb', line 29 def nation @nation end |
#number ⇒ Object
Returns the value of attribute number.
29 30 31 |
# File 'lib/ubi/memorias/address.rb', line 29 def number @number end |
#parts ⇒ Object
Returns the value of attribute parts.
29 30 31 |
# File 'lib/ubi/memorias/address.rb', line 29 def parts @parts end |
#place ⇒ Object
Returns the value of attribute place.
29 30 31 |
# File 'lib/ubi/memorias/address.rb', line 29 def place @place end |
#region ⇒ Object
Returns the value of attribute region.
29 30 31 |
# File 'lib/ubi/memorias/address.rb', line 29 def region @region end |
#words ⇒ Object
Returns the value of attribute words.
29 30 31 |
# File 'lib/ubi/memorias/address.rb', line 29 def words @words end |
#zip ⇒ Object
Returns the value of attribute zip.
29 30 31 |
# File 'lib/ubi/memorias/address.rb', line 29 def zip @zip end |
Class Method Details
.formats ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/ubi/memorias/address.rb', line 74 def formats { # br: '%a, %n - %c %z %r', # br: '%a, %n - %c %z %r', br: '%a, %n - %c %z %r' } end |
.plural ⇒ Object
92 93 94 |
# File 'lib/ubi/memorias/address.rb', line 92 def plural :addresses end |
.regex(hint) ⇒ Object
88 89 90 |
# File 'lib/ubi/memorias/address.rb', line 88 def regex(hint) /(\b(?:#{REGEXES[hint][:prefix].join('|')})\s.*)\b/i end |
.sanitize(txt) ⇒ Object
Sanitizing
“..” -> “.” “n” -> “-” “ -” -> “-”
68 69 70 71 72 |
# File 'lib/ubi/memorias/address.rb', line 68 def sanitize(txt) v = ActiveSupport::Inflector.transliterate(txt) v.gsub(/\s+/, ' ').gsub(/\\n/, '-') .gsub(/\s?(#{DIVIDERS})\s?/, '\1') end |
.zip_format ⇒ Object
82 83 84 85 86 |
# File 'lib/ubi/memorias/address.rb', line 82 def zip_format { br: [/(\d{5})(\d{3})/, '\1-\2'] } end |
Instance Method Details
#fetch_possible ⇒ Object
39 40 41 42 43 44 |
# File 'lib/ubi/memorias/address.rb', line 39 def fetch_possible parse_zip @region = clean.scan(/\W([A-Z]{2})\W/).first @region = @region.first if @region @number = clean.scan(/\d+/).join(' ') end |
#format(location = :br) ⇒ Object
56 57 58 |
# File 'lib/ubi/memorias/address.rb', line 56 def format(location = :br) text #.sub(*self.class.formats[location]) end |
#parse_zip ⇒ Object
32 33 34 35 36 37 |
# File 'lib/ubi/memorias/address.rb', line 32 def parse_zip @zip = text.scan(REGEXES[:br][:zip]).first return unless zip @zip = zip.gsub(/\D/, '').sub(*Address.zip_format[:br]) clean.slice!(zip) end |