jisc-services / eprints-plugin-PubRouter-RIOXXplus-Connector

Eprints plugin, enabling it to accept submissions from Jisc PubRouter via SWORD2 with an enhanced XML schema that enables RIOXX fields to be populated.
GNU Lesser General Public License v3.0
0 stars 3 forks source link

Neater lookup of CC licenses #7

Open adam-rehin opened 5 years ago

adam-rehin commented 5 years ago

https://github.com/jisc-services/eprints-plugin-PubRouter-RIOXXplus-Connector/blob/28717904fc01c5a9c5ebd33c8dc8c37b6d09a04e/lib/plugins/EPrints/Plugin/Import/PubRouter.pm#L77

It would be neater if the my %license_urls map excluded the protocol segment (i.e. http:// and https://) which would reduce its size by 50%, if the code at line 449 used a temporary variable $stripped_lic_url which removes the protocol prefix.

my %license_urls = 
    (
        "creativecommons.org/licenses/by-nd/3.0/" => 'cc_by_nd',
        "creativecommons.org/licenses/by/3.0/" => 'cc_by',
        "creativecommons.org/licenses/by-nc/3.0/" => 'cc_by_nc',
        "creativecommons.org/licenses/by-nc-nd/3.0/" => 'cc_by_nc_nd',
        "creativecommons.org/licenses/by-nd-sa/3.0/" => 'cc_by_nc_sa',
        "creativecommons.org/licenses/by-sa/3.0/" => 'cc_by_sa',
        "creativecommons.org/licenses/by-nd/4.0/" => 'cc_by_nd_4',
        "creativecommons.org/licenses/by/4.0/" => 'cc_by_4',
        "creativecommons.org/licenses/by-nc/4.0/" => 'cc_by_nc_4',
        "creativecommons.org/licenses/by-nc-nd/4.0/" => 'cc_by_nc_nd_4',
        "creativecommons.org/licenses/by-nd-sa/4.0/" => 'cc_by_nc_sa_4',
        "creativecommons.org/licenses/by-sa/4.0/" => 'cc_by_sa_4',
        "creativecommons.org/publicdomain/zero/1.0/legalcode/" => 'cc_public_domain',
        "www.gnu.org/licenses/gpl.html" => 'cc_gnu_gpl',
        "www.gnu.org/licenses/lgpl.html" => 'cc_gnu_lgpl',
    );

https://github.com/jisc-services/eprints-plugin-PubRouter-RIOXXplus-Connector/blob/28717904fc01c5a9c5ebd33c8dc8c37b6d09a04e/lib/plugins/EPrints/Plugin/Import/PubRouter.pm#L449

               my $stripped_lic_url = $license_url;
               $stripped_lic_url =~ s/^https?:\/\///i;    # Remove 'http://' or 'https://' prefix

        if( exists $license_urls{$stripped_lic_url } )
                {
                        $docdata->{license} = $license_urls{$stripped_lic_url};
                }