Class: HovercardPresenter

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/hovercard_presenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(person) ⇒ HovercardPresenter

initialize the presenter with the given Person object

Raises:

  • (ArgumentError)

6
7
8
9
10
# File 'app/presenters/hovercard_presenter.rb', line 6

def initialize(person)
  raise ArgumentError, "the given object is not a Person" unless person.class == Person

  self.person = person
end

Instance Attribute Details

#personObject

Returns the value of attribute person


3
4
5
# File 'app/presenters/hovercard_presenter.rb', line 3

def person
  @person
end

Instance Method Details

#avatar(size = "medium") ⇒ Object

get the image url of the profile avatar for the given size possible sizes: 'small', 'medium', 'large'


26
27
28
29
30
31
32
# File 'app/presenters/hovercard_presenter.rb', line 26

def avatar(size="medium")
  if !["small", "medium", "large"].include?(size)
    raise ArgumentError, "the given parameter is not a valid size"
  end

  person.image_url("thumb_#{size}".to_sym)
end

#profile_urlObject

return the (relative) url to the user profile page. uses the 'person_path' url helper from the rails routes


36
37
38
# File 'app/presenters/hovercard_presenter.rb', line 36

def profile_url
  Rails.application.routes.url_helpers.person_path(person)
end

#to_json(options = {}) ⇒ Object

returns the json representation of the Person object for use with the hovercard UI


14
15
16
17
18
19
20
21
22
# File 'app/presenters/hovercard_presenter.rb', line 14

def to_json(options={})
  {  :id => person.id,
     :avatar => avatar('medium'),
     :url => profile_url,
     :name => person.name,
     :handle => person.diaspora_handle,
     :tags => person.tags.map { |t| "#"+t.name }
  }.to_json(options)
end