public
Created

  • Download Gist
get_positions.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
def get_positions
positions = Position.find_all_by_full_profile_id(current_user.full_profile.id)
if positions.empty?
client = get_client
positions = client.profile(:fields => [:positions]).positions.all
positions.each do |p|
if p.is_current == "true"
Position.create(
title: p.title,
summary: p.summary,
start_date: Date.parse("1/#{p.start_date.month ? p.start_date.month : 1}/#{p.start_date.year}"),
end_date: Date.parse("1/#{p.end_date.month ? p.end_date.month : 1}/#{p.end_date.year}"),
is_current: p.is_current,
company: p.company.name,
full_profile_id: current_user.full_profile.id)
else
Position.create(
title: p.title,
summary: p.summary,
start_date: Date.parse("1/#{p.start_date.month ? p.start_date.month : 1}/#{p.start_date.year}"),
is_current: p.is_current,
company: p.company.name,
full_profile_id: current_user.full_profile.id)
end
end
current_user.full_profile.positions
else
positions
end
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.