Module: Sage

Defined in:
lib/logstash/filters/sage.rb

Class Method Summary collapse

Class Method Details

.parse(input) ⇒ Object



4
5
6
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
# File 'lib/logstash/filters/sage.rb', line 4

def Sage.parse (input)
  uri = URI(URI.unescape(input))

  path = uri.path

  data = {
    "provider" => "sage"
  }

  if (match = /^\/(loi|toc)\/(([a-z]+)\/?([0-9]+)?\/?([0-9]+)?)$/i.match(path))
    data["rtype"] = "TOC"
    data["mime"] = "MISC"
    data["title_id"] = match[3]
    if (match[4])
      data["unit_id"] = match[2]
    end

  elsif (match = /^\/doi\/([a-z]+)\/(([0-9]{2})\.([0-9]{4})\/([0-9]+))$/i.match(path))
    data["rtype"] = "ARTICLE"
    data["mime"] = "HTML"
    data["doi"] = match[2]
    data["unit_id"] = match[5]

    case (match[1])
    when "pdf"
      data["mime"] = "PDF"
    when "figure"
      data["rtype"] = "FIGURE"
    end
  end

  return data

end