Class: ProfileFieldTypes::Address

Inherits:
ProfileField show all
Defined in:
app/models/profile_field_types/address.rb

Overview

Address Information

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ProfileField

#children_count, #delete_cache, #key, #label, #orig_profileable, possible_types, #profileable, #underscored_type, #value

Methods inherited from ActiveRecord::Base

#readonly?

Class Method Details

.model_nameObject



6
# File 'app/models/profile_field_types/address.rb', line 6

def self.model_name; ProfileField.model_name; end

Instance Method Details

#cityObject



43
# File 'app/models/profile_field_types/address.rb', line 43

def city ;          geo_information :city          end

#clear_postal_addressObject



80
81
82
83
84
# File 'app/models/profile_field_types/address.rb', line 80

def clear_postal_address
  self.profileable.profile_fields.where(type: "ProfileFieldTypes::Address").each do |address_field|
    address_field.remove_flag :postal_address
  end
end

#countryObject



41
# File 'app/models/profile_field_types/address.rb', line 41

def country ;       geo_information :country       end

#country_codeObject



42
# File 'app/models/profile_field_types/address.rb', line 42

def country_code ;  geo_information :country_code  end

#display_htmlObject



26
27
28
# File 'app/models/profile_field_types/address.rb', line 26

def display_html
  ActionController::Base.helpers.simple_format self.value
end

#find_geo_locationObject



18
19
20
# File 'app/models/profile_field_types/address.rb', line 18

def find_geo_location
  @geo_location ||= GeoLocation.find_by_address(value)
end

#find_or_create_geo_locationObject



22
23
24
# File 'app/models/profile_field_types/address.rb', line 22

def find_or_create_geo_location
  @geo_location ||= GeoLocation.find_or_create_by address: value if self.value && self.value != ""
end

#geo_information(key) ⇒ Object



47
48
49
50
# File 'app/models/profile_field_types/address.rb', line 47

def geo_information( key )
  return nil if self.value == ""
  geo_location.send( key ) if self.value
end

#geo_locationObject



14
15
16
# File 'app/models/profile_field_types/address.rb', line 14

def geo_location
  find_or_create_geo_location
end

#geocodeObject



55
56
57
58
59
# File 'app/models/profile_field_types/address.rb', line 55

def geocode
  return @geo_location.geocode if @geo_location
  return @geo_location.geocode if find_geo_location
  return find_or_create_geo_location
end

#geocoded?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'app/models/profile_field_types/address.rb', line 52

def geocoded?
  (find_geo_location && @geo_location.geocoded?).to_b
end

#gmapsObject



35
36
37
# File 'app/models/profile_field_types/address.rb', line 35

def gmaps
  true
end

#gmaps4rails_addressObject

This is needed to display the map later.



31
32
33
# File 'app/models/profile_field_types/address.rb', line 31

def gmaps4rails_address
  self.value
end

#latitudeObject



39
# File 'app/models/profile_field_types/address.rb', line 39

def latitude ;      geo_information :latitude      end

#longitudeObject



40
# File 'app/models/profile_field_types/address.rb', line 40

def longitude ;     geo_information :longitude     end

#plzObject



45
# File 'app/models/profile_field_types/address.rb', line 45

def plz ;           geo_information :plz           end

#postal_addressObject

Allow to mark one address as primary postal address.



63
64
65
# File 'app/models/profile_field_types/address.rb', line 63

def postal_address
  self.has_flag? :postal_address
end

#postal_address=(new_postal_address) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
# File 'app/models/profile_field_types/address.rb', line 66

def postal_address=(new_postal_address)
  if new_postal_address != self.postal_address
    if new_postal_address
      self.clear_postal_address
      self.add_flag :postal_address
    else
      self.remove_flag :postal_address
    end
    self.delete_cache
  end
end

#postal_address?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'app/models/profile_field_types/address.rb', line 77

def postal_address?
  self.postal_address
end

#postal_codeObject



44
# File 'app/models/profile_field_types/address.rb', line 44

def postal_code ;   geo_information :postal_code   end