Module: Base::Project::App::Models::Concerns::Addressable

Extended by:
ActiveSupport::Concern
Defined in:
lib/base/project/app/models/concerns/addressable.rb

Instance Method Summary collapse

Instance Method Details

#coordinate_pairObject



69
70
71
# File 'lib/base/project/app/models/concerns/addressable.rb', line 69

def coordinate_pair
  [latitude, longitude]
end

#coordinates_dmsObject



73
74
75
76
77
78
# File 'lib/base/project/app/models/concerns/addressable.rb', line 73

def coordinates_dms
  latitude_dms = coordinate_to_dms(latitude, %w[N S])
  longitude_dms = coordinate_to_dms(longitude, %w[E W])

  [latitude_dms, longitude_dms]
end

#coordinates_precisionObject



38
39
40
41
# File 'lib/base/project/app/models/concerns/addressable.rb', line 38

def coordinates_precision
  self.latitude  = latitude.round(11)  if latitude.present?
  self.longitude = longitude.round(11) if longitude.present?
end

#formatted_completeObject



65
66
67
# File 'lib/base/project/app/models/concerns/addressable.rb', line 65

def formatted_complete
  "#{formatted_simple}, #{formatted_zipcode} #{formatted_country}"
end

#formatted_countryObject



60
61
62
63
# File 'lib/base/project/app/models/concerns/addressable.rb', line 60

def formatted_country
  country_model = ISO3166::Country[country]
  country_model.translations[country] || country_model.name
end

#formatted_simpleObject



47
48
49
50
51
52
53
54
# File 'lib/base/project/app/models/concerns/addressable.rb', line 47

def formatted_simple
  text = "#{street} #{number}"

  text = "#{text}, ap.#{apartment}" if apartment
  text = "#{text}, bl.#{block}" if block

  "#{text}, #{district}, #{city}"
end

#formatted_zipcodeObject



56
57
58
# File 'lib/base/project/app/models/concerns/addressable.rb', line 56

def formatted_zipcode
  StringSanitizer.mask_cep(zipcode)
end

#multiple_default_errorObject



43
44
45
# File 'lib/base/project/app/models/concerns/addressable.rb', line 43

def multiple_default_error
  errors.add(:default, I18n.t('activerecord.errors.messages.default_address_already_exists'))
end