Sha256: 141f7619149492dfd9cd49054d84bab5654d1fe719584dce9805cb2f489f39f9

Contents?: true

Size: 1004 Bytes

Versions: 5

Compression:

Stored size: 1004 Bytes

Contents

module BerkeleyLibrary
  module Holdings
    module WorldCat
      module Symbols
        NRLF = %w[ZAP ZAPSP].freeze
        SRLF = %w[HH0 ZAS ZASSP].freeze
        RLF = (NRLF + SRLF).freeze

        UC = %w[CLU CRU CUI CUN CUS CUT CUV CUX CUY CUZ MERUC].freeze
        ALL = (RLF + UC).freeze

        class << self
          include Symbols
        end

        def valid?(sym)
          ALL.include?(sym)
        end

        def ensure_valid!(symbols)
          raise ArgumentError, "Not a list of institution symbols: #{symbols.inspect}" unless array_like?(symbols)
          raise ArgumentError, 'No institution symbols provided' if symbols.empty?

          return symbols unless (invalid = symbols.reject { |s| Symbols.valid?(s) }).any?

          raise ArgumentError, "Invalid institution symbol(s): #{invalid.map(&:inspect).join(', ')}"
        end

        private

        def array_like?(a)
          %i[reject empty?].all? { |m| a.respond_to?(m) }
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
berkeley_library-holdings-1.0.5 lib/berkeley_library/holdings/world_cat/symbols.rb
berkeley_library-holdings-1.0.4 lib/berkeley_library/holdings/world_cat/symbols.rb
berkeley_library-holdings-1.0.3 lib/berkeley_library/holdings/world_cat/symbols.rb
berkeley_library-holdings-1.0.2 lib/berkeley_library/holdings/world_cat/symbols.rb
berkeley_library-holdings-1.0.1 lib/berkeley_library/holdings/world_cat/symbols.rb