class EzproxyProviders::Jstor

Public Class Methods

parse(path, params) click to toggle source
# File lib/logstash/filters/ezproxy_providers/jstor.rb, line 4
def self.parse (path, params)

    data = {
        "provider" => "jstor"
    }
    doi_prefix = "10.2307"


    if (match = /^\/journal\/([a-z0-9]+)$/i.match(path))
        data["rtype"] = "TOC"
        data["mime"] = "MISC"
        data["unit_id"] = match[1]
        data["title_id"] = match[1]

    elsif (match = /^\/stable\/10\.[0-9]+\/(([a-z]+)\.([0-9]+)\.([0-9]+)\.issue-([0-9]+))$/i.match(path))
        data["rtype"] = "TOC"
        data["mime"] = "MISC"
        data["unit_id"] = match[1]
        data["title_id"] = match[2]
        data["issue"] = match[5]

        if match[3].length >= 4
            data["publication_date"] = match[3]
            data["vol"] = match[4]
        else
            data["vol"] = match[3]
        end

    elsif (match = /^\/stable\/((10\.[0-9]+\/)?([a-z0-9]+))$/i.match(path))
        data["rtype"] = "TOC"
        data["mime"] = "MISC"
        data["unit_id"] = match[3]
        data["title_id"] = match[3]

        if match[2]
            data["doi"] = match[1]
        end

    elsif (match =  /^\/stable\/(i[0-9]+)$/i.match(path))
        data["rtype"] = "TOC"
        data["mime"] = "MISC"
        data["unit_id"] = match[1]
        data["title_id"] = match[1]

    elsif (/^\/action\/showPublication$/i.match(path))
        if (params["journalCode"])
            data["title_id"] = params["journalCode"][0]
            data["unit_id"] = params["journalCode"][0]
            data["rtype"] = 'TOC'
            data["mime"] = 'MISC'
        end

    elsif (match =  /^\/stable\/(get_image|pdf|pdfplus)\/((10\.[0-9]+\/)?([a-z0-9.]+?))(?:\.pdf)?$/i.match(path))
        data["unit_id"] = match[4]
        data["doi"] = match[3] ? match[2] : doi_prefix + "/" + match[2] 
        
        case match[1]
        when 'get_image'
            data["rtype"] = "ARTICLE_SECTION"
            data["mime"] = "GIF"
        when 'pdf'
            data["rtype"] = "ARTICLE"
            data["mime"] = "PDF"
        when 'pdfplus'
            data["rtype"] = "ARTICLE"
            data["mime"] = "PDFPLUS"
        end

        idPattern = /^([a-z0-9]+)((?:\.(\d+))?\.(\d+)\.(\d+)\.(\w+))?/.match(match[4]) || [];

        data["title_id"] = idPattern[1]
        data["publication_date"] = idPattern[3]
        data["vol"] = idPattern[4]
        data["issue"] = idPattern[5]

        if (idPattern[6] == 'cover')
            data["rtype"] = 'COVER'
        elsif (idPattern[6] == 'toc')
            data["rtype"] = 'TOC'
        else
            if (idPattern[6] != nil)
                first_page = idPattern[6].to_i
                
                unless (first_page.to_f.nan?)
                    data["first_page"] = first_page.to_s
                end
            end
        end

    elsif (match = /^\/stable\/(info|view)\/([0-9]+)$/i.match(path))
        data["rtype"] = match[1] === 'info' ? "ABS" : "PREVIEW"
        data["mime"] = "MISC"
        data["unit_id"] = match[2]
        data["title_id"] = match[2]
        data["issue"] = match[5]
    end

    return data
end