Module: Orcid::Remote::ProfileQueryService::QueryParameterBuilder

Defined in:
app/services/orcid/remote/profile_query_service/query_parameter_builder.rb

Overview

Class Method Summary collapse

Class Method Details

.call(input = {}) ⇒ Object

Responsible for converting an arbitrary query string to the acceptable Orcid query format.

point of entry



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/services/orcid/remote/profile_query_service/query_parameter_builder.rb', line 14

def call(input = {})
  params = {}
  q_params = []
  text_params = []
  input.each do |key, value|
    next if value.nil? || value.to_s.strip == ''
    case key.to_s
    when 'start', 'row'
      params[key] = value
    when 'q', 'text'
      text_params << "#{value}"
    else
      q_params << "#{key.to_s.gsub('_', '-')}:#{value}"
    end
  end

  case text_params.size
  when 0; then nil
  when 1
    q_params << "text:#{text_params.first}"
  else
    q_params << "text:((#{text_params.join(') AND (')}))"
  end
  params[:q] = q_params.join(' AND ')
  params
end