Commit 3a33d6e9 authored by Hussain Kashef's avatar Hussain Kashef

refactored language skills into a class method

parent 996d3639
Pipeline #51292 failed with stage
in 38 minutes and 40 seconds
......@@ -15,19 +15,25 @@ class LanguageSkill < ApplicationRecord
where.not(id: native_language.id)
}
def self.languages
@languages ||= I18n.t('language_names').merge(I18n.t('language_names_customizations'))
.map { |key, lang| [lang, key.to_s] }.sort
end
class << self
def languages
@languages ||= I18n.t('language_names').merge(I18n.t('language_names_customizations'))
.map { |key, lang| [lang, key.to_s] }.sort
end
def self.native_language
native_languages.first || LanguageSkill.new
end
def native_language
native_languages.first || LanguageSkill.new
end
def self.language_name(language)
return '' if language.blank?
I18n.t("language_names.#{language}")
def language_name(language)
return '' if language.blank?
I18n.t("language_names.#{language}")
end
def native_and_human_readable
german_first.native_languages.map(&:full_language_skills)
end
end
def language_name
......@@ -37,5 +43,5 @@ class LanguageSkill < ApplicationRecord
def full_language_skills
level_human = level? ? I18n.t(level, scope: [:language_level]) : ''
[language_name, level_human].reject(&:blank?).join(', ') if language?
end
end
end
......@@ -24,8 +24,8 @@ tr id=dom_id(client)
br
td= nationality_name(client.nationality)
td.language-skill-index
- [client.language_skills.german, client.language_skills.native_languages].flatten.each do |language|
span= language.full_language_skills
- client.language_skills.native_and_human_readable.each do |language_readable|
span= language_readable
td= client.goals
td= client.interests
- if policy(Client).superadmin_privileges?
......
......@@ -84,10 +84,6 @@ wb.add_worksheet(name: t('clients_xlsx')) do |sheet|
clients.each do |client|
language_skills = Array.new()
[client.language_skills.german, client.language_skills.native_languages].flatten.each do |language|
language_skills.push("#{language.full_language_skills}")
end.compact
salutation = t("salutation.#{client.salutation}") if client.salutation?
contact = client.contact
body_row = [
......@@ -108,7 +104,7 @@ wb.add_worksheet(name: t('clients_xlsx')) do |sheet|
client.entry_date, # 14
t("acceptance.#{client.acceptance}"), # 15
client.involved_authority, # 16
language_skills.join("\r"), # 17
client.language_skills.native_and_human_readable.join("\r"), # 17
client.goals, # 18
client.created_at.in_time_zone, # 19
client.updated_at.in_time_zone # 20
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment