Class: Address

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document
Defined in:
lib/address.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.address_fieldsObject



16
17
18
# File 'lib/address.rb', line 16

def self.address_fields
  %w{street number floor_adr} + geo_address_fields
end

.all_geo_address_fieldsObject



12
13
14
# File 'lib/address.rb', line 12

def self.all_geo_address_fields
  geo_address_fields + %w{latitude longitude}
end

.geo_address_fieldsObject



8
9
10
# File 'lib/address.rb', line 8

def self.geo_address_fields
  %w{city state state_code province province_code postal_code country country_code}
end

.type_of(name) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/address.rb', line 20

def self.type_of name
  case name.to_sym
  when :latitude, :longitude, :postal_code
    :int
  else
    :string
  end
end

Instance Method Details

#floorObject



41
42
43
# File 'lib/address.rb', line 41

def floor
  floor_adr.to_i
end

#geolocatable?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/address.rb', line 59

def geolocatable?
  !full.blank?
end

#perform_geocodingObject Also known as: perform_geocoding!



63
64
65
66
# File 'lib/address.rb', line 63

def perform_geocoding
  return unless geolocatable?
  addressable.perform_geocoding if addressable.respond_to? :perform_geocoding
end

#regionObject



45
46
47
# File 'lib/address.rb', line 45

def region
  state || province
end

#to_sObject



53
54
55
56
57
# File 'lib/address.rb', line 53

def to_s
  Address.address_fields.inject("") do |res, name|
    res << "#{name}: #{send(name)}\n"
  end
end

#xtra_fieldsObject



49
50
51
# File 'lib/address.rb', line 49

def xtra_fields
  [:floor_adr]
end