Skip to content
This repository was archived by the owner on Mar 23, 2023. It is now read-only.

Commit 16f7500

Browse files
Refactor to_twitter method on job class
1 parent 182c220 commit 16f7500

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

app/models/job.rb

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -216,18 +216,22 @@ def to_text_for_social_media
216216
end
217217

218218
def to_text_for_twitter
219-
text = "text=#{self.company_name.titleize} is looking to hire a #{self.title}"
220-
text += " in #{self.location_name}" unless self.location_name.blank?
221-
text += ". More information here&url=https://#{AppSettings.application_host}/jobs/#{self.to_param}&hashtags=#{self.location_name}"
222-
if !self.twitter_handle.blank?
223-
if self.twitter_handle.start_with?('@')
224-
text += (" " + self.twitter_handle)
225-
else
226-
text += (" @" + self.twitter_handle)
227-
end
219+
job_location, job_hashtags = "", ""
220+
job_company_name = self.company_name.titleize
221+
job_title = self.title
222+
223+
unless self.location_name.blank?
224+
job_location = "in #{self.location_name}"
225+
job_hashtags = "&hashtags=#{self.location_name}"
226+
end
227+
228+
job_link = "&url=https://#{AppSettings.application_host}/jobs/#{self.to_param}"
229+
230+
unless self.twitter_handle.blank?
231+
job_twitter_account = clean_twitter_handle
228232
end
229233

230-
return text
234+
return "text=#{job_company_name} is looking to hire a #{job_title} #{job_location}. More information here#{job_link}#{job_twitter_account}"
231235
end
232236

233237
private
@@ -246,4 +250,12 @@ def strip_whitespace
246250
self.company_name = self.company_name.strip unless self.company_name.nil?
247251
self.apply_email = self.apply_email.strip unless self.apply_email.nil?
248252
end
253+
254+
def clean_twitter_handle
255+
if self.twitter_handle.start_with?('@')
256+
return (" " + self.twitter_handle)
257+
else
258+
return (" @" + self.twitter_handle)
259+
end
260+
end
249261
end

app/views/jobs/_job_info_sidebar.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
<% if @job.online? %>
1414
<hr/>
1515
<div class="center-content">
16-
<%= link_to("Apply for this position", @job.external_link, class: "button button-3d button-small", target: "_blank") %>
16+
<%= link_to("Apply for this position", h(@job.external_link), class: "button button-3d button-small") %>
1717

1818
<% unless @job.apply_email.blank? %>
19-
<%= mail_to(@job.apply_email, "Apply via email", class: "button button-3d button-yellow button-small", target: "_blank") %>
19+
<%= mail_to(@job.apply_email, "Apply via email", class: "button button-3d button-yellow button-small") %>
2020
<% end %>
2121
</div>
2222
<% end %>

0 commit comments

Comments
 (0)