Class: PersonPresenter

Inherits:
BasePresenter show all
Defined in:
app/presenters/person_presenter.rb

Instance Attribute Summary

Attributes inherited from BasePresenter

#current_user

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BasePresenter

as_collection, #initialize, #method_missing, new

Constructor Details

This class inherits a constructor from BasePresenter

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class BasePresenter

Class Method Details

.people_names(people) ⇒ Object


68
69
70
# File 'app/presenters/person_presenter.rb', line 68

def self.people_names(people)
  people.map(&:name).join(", ")
end

Instance Method Details

#as_api_jsonObject


13
14
15
16
17
18
19
20
# File 'app/presenters/person_presenter.rb', line 13

def as_api_json
  {
    guid:        guid,
    diaspora_id: diaspora_handle,
    name:        name,
    avatar:      AvatarPresenter.new(@presentable).medium
  }.compact
end

#as_json(_options = {}) ⇒ Object


45
46
47
# File 'app/presenters/person_presenter.rb', line 45

def as_json(_options={})
  full_hash_with_profile
end

#base_hashObject


4
5
6
7
8
9
10
11
# File 'app/presenters/person_presenter.rb', line 4

def base_hash
  {
    id:          id,
    guid:        guid,
    name:        name,
    diaspora_id: diaspora_handle
  }
end

#full_hashObject


22
23
24
25
26
27
28
29
# File 'app/presenters/person_presenter.rb', line 22

def full_hash
  base_hash_with_contact.merge(
    relationship:      relationship,
    block:             is_blocked? ? BlockPresenter.new(current_user_person_block).base_hash : false,
    is_own_profile:    own_profile?,
    show_profile_info: public_details? || own_profile? || person_is_following_current_user
  )
end

#hovercardObject


49
50
51
# File 'app/presenters/person_presenter.rb', line 49

def hovercard
  base_hash_with_contact.merge(profile: ProfilePresenter.new(profile).for_hovercard)
end

#metas_attributesObject


53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'app/presenters/person_presenter.rb', line 53

def metas_attributes
  {
    keywords:             {name:     "keywords",    content: comma_separated_tags},
    description:          {name:     "description", content: description},
    og_title:             {property: "og:title",    content: title},
    og_description:       {property: "og:title",    content: description},
    og_url:               {property: "og:url",      content: url},
    og_image:             {property: "og:image",    content: image_url},
    og_type:              {property: "og:type",     content: "profile"},
    og_profile_username:  {property: "og:profile:username",   content: name},
    og_profile_firstname: {property: "og:profile:first_name", content: first_name},
    og_profile_lastname:  {property: "og:profile:last_name",  content: last_name}
  }
end

#profile_hash_as_api_jsonObject


31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/presenters/person_presenter.rb', line 31

def profile_hash_as_api_json
  if own_profile?
    ProfilePresenter.new(profile).as_self_api_json.merge(guid: guid)
  else
    show_detailed = @presentable.public_details? || person_is_following_current_user
    ProfilePresenter.new(profile).as_other_api_json(show_detailed).merge(
      guid:         guid,
      blocked:      is_blocked?,
      relationship: relationship_detailed,
      aspects:      aspects_detailed
    )
  end
end