Class: Europeana::API::Record

Inherits:
Object
  • Object
show all
Includes:
Resource
Defined in:
lib/europeana/api/record.rb,
lib/europeana/api/record/lang_map.rb

Overview

Interface to the Europeana API Record method

Defined Under Namespace

Modules: LangMap

Class Method Summary collapse

Class Method Details

.escape(text) ⇒ String

Escapes Lucene syntax special characters for use in query parameters.

The ‘Europeana::API` gem does not perform this escaping itself. Applications using the gem are responsible for escaping parameters when needed.

Parameters:

  • text (String)

    Text to escape

Returns:

  • (String)

    Escaped text



36
37
38
39
40
41
42
# File 'lib/europeana/api/record.rb', line 36

def escape(text)
  fail ArgumentError, "Expected String, got #{text.class}" unless text.is_a?(String)
  specials = %w<\\ + - & | ! ( ) { } [ ] ^ " ~ * ? : />
  specials.each_with_object(text.dup) do |char, unescaped|
    unescaped.gsub!(char, '\\\\' + char) # prepends *one* backslash
  end
end