Module: ProfileableMixins::Address
- Extended by:
- ActiveSupport::Concern
- Included in:
- User
- Defined in:
- app/models/profileable_mixins/address.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#address_fields ⇒ Object
Scope for profile fields that are postal addresses.
-
#home_address ⇒ Object
The postal address of the user’s home.
- #home_address=(address_string) ⇒ Object
- #home_address_labels ⇒ Object
-
#postal_address ⇒ Object
This method returns the postal address of the user.
-
#postal_address_field ⇒ Object
Primary Postal Address.
-
#postal_address_field_or_first_address_field ⇒ Object
Primary Postal Address or, if not existent, the first address field.
- #postal_address_in_one_line ⇒ Object
-
#postal_address_updated_at ⇒ Object
Returns when the postal address has been updated last.
-
#study_address ⇒ Object
The postal address at the study location.
- #study_address=(address_string) ⇒ Object
- #study_address_labels ⇒ Object
-
#work_address ⇒ Object
The postal address of the work place.
- #work_address=(address_string) ⇒ Object
- #work_address_labels ⇒ Object
- #work_or_study_address ⇒ Object
- #work_or_study_address_labels ⇒ Object
Instance Method Details
#address_fields ⇒ Object
Scope for profile fields that are postal addresses.
6 7 8 |
# File 'app/models/profileable_mixins/address.rb', line 6 def address_fields self.id ? profile_fields.where(type: 'ProfileFieldTypes::Address') : profile_fields.where('false') end |
#home_address ⇒ Object
The postal address of the user’s home.
49 50 51 |
# File 'app/models/profileable_mixins/address.rb', line 49 def home_address address_fields.where(label: home_address_labels).first.try(:value) end |
#home_address=(address_string) ⇒ Object
52 53 54 55 56 |
# File 'app/models/profileable_mixins/address.rb', line 52 def home_address=(address_string) field = address_fields.where(label: home_address_labels).first || address_fields.build(label: home_address_labels.first) field.value = address_string field.save end |
#home_address_labels ⇒ Object
57 58 59 |
# File 'app/models/profileable_mixins/address.rb', line 57 def home_address_labels ["Heimatanschrift", "Private Anschrift", "Home Address"] end |
#postal_address ⇒ Object
This method returns the postal address of the user. If one address of the user has got a :postal_address flag, this address is used. Otherwise, the first address of the user is used.
79 80 81 |
# File 'app/models/profileable_mixins/address.rb', line 79 def postal_address cached { postal_address_field_or_first_address_field.try(:value) } end |
#postal_address_field ⇒ Object
Primary Postal Address
63 64 65 66 67 |
# File 'app/models/profileable_mixins/address.rb', line 63 def postal_address_field self.address_profile_fields.select do |address_field| address_field.postal_address? == true end.first end |
#postal_address_field_or_first_address_field ⇒ Object
Primary Postal Address or, if not existent, the first address field.
71 72 73 |
# File 'app/models/profileable_mixins/address.rb', line 71 def postal_address_field_or_first_address_field postal_address_field || address_profile_fields.where("value != ? AND NOT value IS NULL", '').first end |
#postal_address_in_one_line ⇒ Object
83 84 85 |
# File 'app/models/profileable_mixins/address.rb', line 83 def postal_address_in_one_line postal_address.split("\n").collect { |line| line.strip }.join(", ") if postal_address end |
#postal_address_updated_at ⇒ Object
Returns when the postal address has been updated last.
89 90 91 92 93 94 95 96 97 98 |
# File 'app/models/profileable_mixins/address.rb', line 89 def postal_address_updated_at cached do # if the date is earlier, the date is actually the date # of the data migration and should not be shown. # if postal_address_field_or_first_address_field && postal_address_field_or_first_address_field.updated_at.to_date > "2014-02-28".to_date postal_address_field_or_first_address_field.updated_at.to_date end end end |
#study_address ⇒ Object
The postal address at the study location.
12 13 14 |
# File 'app/models/profileable_mixins/address.rb', line 12 def study_address address_fields.where(label: study_address_labels + work_or_study_address_labels).first.try(:value) end |
#study_address=(address_string) ⇒ Object
15 16 17 18 19 20 |
# File 'app/models/profileable_mixins/address.rb', line 15 def study_address=(address_string) field = address_fields.where(label: study_address_labels + work_or_study_address_labels).first || address_fields.build(label: study_address_labels.first) field.value = address_string field.label = study_address_labels.first if field.label.in? work_or_study_address_labels field.save end |
#study_address_labels ⇒ Object
21 22 23 |
# File 'app/models/profileable_mixins/address.rb', line 21 def study_address_labels ["Semesteranschrift", "Studienanschrift", "Study Address"] end |
#work_address ⇒ Object
The postal address of the work place.
34 35 36 |
# File 'app/models/profileable_mixins/address.rb', line 34 def work_address address_fields.where(label: work_address_labels + work_or_study_address_labels).first.try(:value) end |
#work_address=(address_string) ⇒ Object
37 38 39 40 41 42 |
# File 'app/models/profileable_mixins/address.rb', line 37 def work_address=(address_string) field = address_fields.where(label: work_address_labels + work_or_study_address_labels).first || address_fields.build(label: work_address_labels.first) field.label = work_address_labels.first if field.label.in? work_or_study_address_labels field.value = address_string field.save end |
#work_address_labels ⇒ Object
43 44 45 |
# File 'app/models/profileable_mixins/address.rb', line 43 def work_address_labels ["Geschäftliche Anschrift", "Arbeitsanschrift", "Dienstanschrift", "Work Address"] end |
#work_or_study_address ⇒ Object
25 26 27 |
# File 'app/models/profileable_mixins/address.rb', line 25 def work_or_study_address work_address || study_address end |
#work_or_study_address_labels ⇒ Object
28 29 30 |
# File 'app/models/profileable_mixins/address.rb', line 28 def work_or_study_address_labels ["Arbeits- oder Studienanschrift", "Work or Study Address"] end |