Sha256: 61d332f12e897f4b439e398ae6db3398aa0c7d26cb92e60145c64eb94ce058be

Contents?: true

Size: 1.83 KB

Versions: 1

Compression:

Stored size: 1.83 KB

Contents

require 'stanford-mods/searchworks_languages'

# # SearchWorks specific wranglings of MODS metadata as an extension of the Mods::Record object
module Stanford
  module Mods

    class Record < ::Mods::Record
      
      # if it's coming from DOR, then it is available online
      def access_facet
        ['Online']
      end
      
      # include langagues known to SearchWorks; try to error correct when possible (e.g. when ISO-639 disagrees with MARC standard)
      def language_facet
        result = []
        @mods_ng_xml.language.each { |n| 
          # get languageTerm codes and add their translations to the result
          n.code_term.each { |ct| 
            if ct.authority.match(/^iso639/)
              begin
                vals = ct.text.split(/[,|\ ]/).reject {|x| x.strip.length == 0 } 
                vals.each do |v|
                  iso639_val = ISO_639.find(v.strip).english_name
                  if SEARCHWORKS_LANGUAGES.has_value?(iso639_val)
                    result << iso639_val
                  else
                    result << SEARCHWORKS_LANGUAGES[v.strip]
                  end
                end
              rescue => e
                p "Couldn't find english name for #{ct.text}"
                result << SEARCHWORKS_LANGUAGES[v.strip]
              end
            else
              result << SEARCHWORKS_LANGUAGES[v.strip]
            end
          }
          # add languageTerm text values
          n.text_term.each { |tt| 
            val = tt.text.strip
            result << val if val.length > 0 && SEARCHWORKS_LANGUAGES.has_value?(val)
          }

          # add language values that aren't in languageTerm subelement
          if n.languageTerm.size == 0
            result << n.text if SEARCHWORKS_LANGUAGES.has_value?(n.text)
          end
        }
        result.uniq
      end
      
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stanford-mods-0.0.3 lib/stanford-mods/searchworks.rb