Module: SortNameProcessor::Person

Defined in:
backend/app/model/mixins/sort_name_processor.rb

Class Method Summary collapse

Class Method Details

.process(json, extras = {}) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'backend/app/model/mixins/sort_name_processor.rb', line 103

def self.process(json, extras = {})
  result = ""

  if json["name_order"] === "inverted"
    result << json["primary_name"] if json["primary_name"]
    result << ", #{json["rest_of_name"]}" if json["rest_of_name"]
  elsif json["name_order"] === "direct"
    result << json["rest_of_name"] if json["rest_of_name"]
    result << " #{json["primary_name"]}" if json["primary_name"]
  else
    result << json["primary_name"]
  end

  result << ", #{json["prefix"]}" if json["prefix"]
  result << ", #{json["suffix"]}" if json["suffix"]
  result << ", #{json["title"]}" if json["title"]
  result << ", #{json["number"]}" if json["number"]
  result << " (#{json["fuller_form"]})" if json["fuller_form"]
  result << ", #{json["dates"]}" if json["dates"]
  result << " (#{json["qualifier"]})" if json["qualifier"]

  dates = json['dates'].nil? ? SortNameProcessor::Utils.first_date(extras, 'dates_of_existence') : nil
  result << " (#{dates})" if dates

  result.lstrip!
  result.length > 255 ? result[0..254] : result
end