Module: Helpers

Included in:
Serrano::Request, Serrano::RequestCursor
Defined in:
lib/serrano/filterhandler.rb

Overview

helper functions

Instance Method Summary collapse

Instance Method Details

#filter_handler(x = nil) ⇒ Object



7
8
9
10
11
12
13
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
40
41
42
43
# File 'lib/serrano/filterhandler.rb', line 7

def filter_handler(x = nil)
  if x.nil?
    nil
  else
    x = stringify(x)
    nn = x.keys.collect{ |z| z.to_s }
    if nn.collect{ |w| $others.include? w }.any?
      nn = nn.collect{ |b|
        if $others.include? b
          case b
          when 'license_url'
            'license.url'
          when 'license_version'
            'license.version'
          when 'license_delay'
            'license.delay'
          when 'full_text_version'
            'full-text.version'
          when 'full_text_type'
            'full-text.type'
          when 'award_number'
            'award.number'
          when 'award_funder'
            'award.funder'
          end
        else
          b
        end
      }
    end

    newnn = nn.collect{ |m| m.gsub("_", "-") }
    x = rename_keys(x, newnn)
    x = x.collect{ |k,v| [k, v].join(":") }.join(',')
    return x
  end
end

#rename_keys(x, y) ⇒ Object



49
50
51
# File 'lib/serrano/filterhandler.rb', line 49

def rename_keys(x, y)
  (y.zip x.values).to_h
end

#stringify(x) ⇒ Object



45
46
47
# File 'lib/serrano/filterhandler.rb', line 45

def stringify(x)
  (x.keys.map{ |k,v| k.to_s }.zip x.values).to_h
end