Class: Profile

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ActiveModel::ForbiddenAttributesProtection
Defined in:
app/models/profile.rb

Instance Method Summary collapse

Instance Method Details

#ageObject



44
45
46
47
48
# File 'app/models/profile.rb', line 44

def age
  return nil if self.birthday.blank? 
  now = Time.now.utc.to_date
  now.year - self.birthday.year - (self.birthday.to_date.change(:year => now.year) > now ? 1 : 0)
end

#as_json(options = nil) ⇒ Object



83
84
85
86
87
88
89
# File 'app/models/profile.rb', line 83

def as_json options = nil
  {
    nickName: slug,
    displayName: name,
    email: email,
  }
end

#birthday=(value) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/models/profile.rb', line 29

def birthday=(value)
  if value.blank?
    @birthday_formatted_invalid = false    
    super value
  else
    begin
      #super Date.parse(value)
      super value
      @birthday_formatted_invalid = false
    rescue 
      @birthday_formatted_invalid = true
    end
  end
end

#contact_present?Boolean

Returns true if the “Contact Information” section is empty

Returns:

  • (Boolean)


70
71
72
73
74
75
76
# File 'app/models/profile.rb', line 70

def contact_present?
  phone? ||
    mobile? ||
    fax? ||
    address? ||
    website?
end

#owner?(subject) ⇒ Boolean

Tells if the subject accessing the profile is its owner or not

Returns:

  • (Boolean)


56
57
58
59
# File 'app/models/profile.rb', line 56

def owner?(subject)
  subject.present? &&
    actor_id == Actor.normalize_id(subject)
end

#personal_present?Boolean

Returns true if the “Personal Information” section is empty

Returns:

  • (Boolean)


62
63
64
65
66
67
# File 'app/models/profile.rb', line 62

def personal_present?
  organization? ||
    birthday? || 
    city? ||
    description?
end

#subjectObject

The subject of this profile



51
52
53
# File 'app/models/profile.rb', line 51

def subject
  actor.try(:subject)
end

#tags_present?Boolean

True if the profile owner has tags attached

Returns:

  • (Boolean)


79
80
81
# File 'app/models/profile.rb', line 79

def tags_present?
  actor.tag_list.count > 0
end