class Celsius::Primo::SoapApi::Searcher::SearchBrief::SearchResultTransformation::ProcessRecords
Public Instance Methods
call()
click to toggle source
# File lib/celsius/primo/soap_api/searcher/search_brief/search_result_transformation/process_records.rb, line 7 def call add_records!(transformation.target).each do |record| [ { "_source/control/recordid" => "_id" }, { "_source/display/creator" => "creator" }, { "_source/display/creationdate" => "created" }, { "_source/display/description" => "description" }, { "_source/display/edition" => "edition" }, { "_source/display/format" => "format" }, { "_source/control/ilsapiid" => "identifier" }, { "_source/control/recordid" => "identifier" }, { "_source/search/isbn" => "isbn" }, { "_source/search/issn" => "issn" }, { "_source/display/language" => "language" }, { "_source/display/title" => "title" }, { "_source/display/publisher" => "publisher" }, { "_source/display/subject" => "subject" } ].each do |mapping| source = resolve_path(record, mapping.keys.first) target = resolve_path(record, mapping.values.first, -2) target_key = mapping.values.first.split("/").last Celsius::Hash.smart_store(target, target_key, deep_clone(source)) end add_place_of_publication!(record) end end
Private Instance Methods
add_place_of_publication!(record)
click to toggle source
# File lib/celsius/primo/soap_api/searcher/search_brief/search_result_transformation/process_records.rb, line 39 def add_place_of_publication!(record) if record["publisher"] && !record["placeOfPublication"] places_seperated_from_publishers = ensure_array(record["publisher"]).map do |publisher| publisher.match(/(\A[^:]*):(.*)/).captures.map(&:strip) end places_of_publication, publishers = [], [] places_seperated_from_publishers.each.with_index do |place_and_publisher, index| places_of_publication[index] = place_and_publisher.first publishers[index] = place_and_publisher.last end record["placeOfPublication"] = collapse_array(places_of_publication) record["publisher"] = collapse_array(publishers) end end
add_records!(target)
click to toggle source
# File lib/celsius/primo/soap_api/searcher/search_brief/search_result_transformation/process_records.rb, line 57 def add_records!(target) (search_brief_return.locate("JAGROOT/RESULT/DOCSET/DOC") || []).each do |source_record| target["hits"]["hits"].push({ "_type" => "record", "_source" => source_record.locate("PrimoNMBib/record/?").inject({}) do |_source, section| _source.merge! section.value => transformation.hash_from_ox_element(section) end }) end target["hits"]["hits"] # for chaining end
collapse_array(array)
click to toggle source
# File lib/celsius/primo/soap_api/searcher/search_brief/search_result_transformation/process_records.rb, line 70 def collapse_array(array) array.length == 1 ? array.first : array end
deep_clone(object)
click to toggle source
# File lib/celsius/primo/soap_api/searcher/search_brief/search_result_transformation/process_records.rb, line 74 def deep_clone(object) Marshal.load(Marshal.dump(object)) end
ensure_array(object)
click to toggle source
# File lib/celsius/primo/soap_api/searcher/search_brief/search_result_transformation/process_records.rb, line 78 def ensure_array(object) object.is_a?(Array) ? object : [object] end
resolve_path(object, path, level = -1)
click to toggle source
# File lib/celsius/primo/soap_api/searcher/search_brief/search_result_transformation/process_records.rb, line 82 def resolve_path(object, path, level = -1) path.split("/").slice(0..level).inject(object) do |_object, key| _object[key] unless _object.nil? end end