From 64d837d5cadee36af85e581ecde899a06b2c8b2c Mon Sep 17 00:00:00 2001 From: BoHung Chiu Date: Tue, 3 Oct 2023 00:05:30 +0800 Subject: [PATCH] Fix author text bug. --- app/helpers/admin/journal_papers_helper.rb | 37 +++++++++++++++------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/app/helpers/admin/journal_papers_helper.rb b/app/helpers/admin/journal_papers_helper.rb index f4a7f6f..e8f52c4 100644 --- a/app/helpers/admin/journal_papers_helper.rb +++ b/app/helpers/admin/journal_papers_helper.rb @@ -3,27 +3,42 @@ module Admin::JournalPapersHelper authors_text = Nokogiri::HTML(journal.authors.to_s).text split_text = authors_text.match(/[、,,\/]/) split_text = split_text.nil? ? '/' : split_text[0] - full_authors_names = get_member(journal).collect(&:name) if authors_text.present? - authors_names = authors_text.split(split_text).select{|a| !(full_authors_names.include?(a.strip()))} - full_authors_names += authors_names + authors_names = authors_text.split(split_text) + else + authors_names = [] end + full_authors_names = get_member(journal).collect do |member| + member_name = member.name + idx = authors_names.index{|a| a.chomp('*') == member_name} + if idx + member_name = authors_names[idx] + authors_names[idx] = nil + end + member_name + end + full_authors_names += authors_names.compact full_authors_names.join(split_text) end def get_authors_show(journal) authors_text = Nokogiri::HTML(journal.authors.to_s).text split_text = authors_text.match(/[、,,\/]/) split_text = split_text.nil? ? '/' : split_text[0] - full_authors_names = [] - full_authors = get_member(journal).collect{|member| - member_name = member.name - full_authors_names << member_name - "#{member_name}" - } if authors_text.present? - authors_names = authors_text.split(split_text).select{|a| !(full_authors_names.include?(a.strip()))} - full_authors += authors_names + authors_names = authors_text.split(split_text) + else + authors_names = [] end + full_authors = get_member(journal).collect do |member| + member_name = member.name + idx = authors_names.index{|a| a.chomp('*') == member_name} + if idx + member_name = authors_names[idx] + authors_names[idx] = nil + end + "#{member_name}" + end + full_authors += authors_names.compact full_authors.join(split_text) end def get_member(journal)