Untitled
unknown
plain_text
2 years ago
942 B
6
Indexable
def get_working_permit_str(job) return unless job.working_permits.present? && job.working_permits.size >= 1 countries = job.working_permits wp_str = '' if countries.size == 1 wp_str = "#{countries[0]['name']} only" elsif countries.size > 1 alpha2_cty = countries.map do |c| if c['type'] == 'country' && Country.find_country_by_any_name(c['name']).present? && Country.find_country_by_any_name(c['name']).alpha2.present? Country.find_country_by_any_name(c['name']).alpha2 else c['name'] end end if countries.size == 2 wp_str = "#{alpha2_cty[0]} & #{alpha2_cty[1]}" elsif countries.size == 3 wp_str = "#{alpha2_cty[0]}, #{alpha2_cty[1]} & #{alpha2_cty[2]}" elsif countries.size > 3 wp_str = "#{alpha2_cty[0]}, #{alpha2_cty[1]} + #{alpha2_cty.size - 2} more only" end end wp_str end
Editor is loading...