Method: BaseHelper#profile_completeness

Defined in:
app/helpers/base_helper.rb

#profile_completeness(user) ⇒ Object



327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# File 'app/helpers/base_helper.rb', line 327

def profile_completeness(user)
  segments = [
    {:val => 2, :action => link_to(:upload_a_profile_photo.l, edit_user_path(user, :anchor => 'profile_details')), :test => !user.avatar.nil? },
    {:val => 1, :action => link_to(:tell_us_about_yourself.l, edit_user_path(user, :anchor => 'user_description')), :test => !user.description.blank?},
    {:val => 2, :action => link_to(:select_your_city.l, edit_user_path(user, :anchor => 'location_chooser')), :test => !user.metro_area.nil? },
    {:val => 1, :action => link_to(:tag_yourself.l, edit_user_path(user, :anchor => "user_tags")), :test => user.tags.any?},
    {:val => 1, :action => link_to(:invite_some_friends.l, new_invitation_path), :test => user.invitations.any?}
  ]

  completed_score = segments.select{|s| s[:test].eql?(true)}.sum{|s| s[:val]}
  incomplete = segments.select{|s| !s[:test] }

  total = segments.sum{|s| s[:val] }
  score = (completed_score.to_f/total.to_f)*100

  {:score => score, :incomplete => incomplete, :total => total}
end