app/models/work.rb
# find Creative Commons or OSI license in rightsURI array
find Creative Commons or OSI license in rightsURI array
find Creative Commons or OSI license in rightsURI array
def normalize_license(licenses)
    uri = licenses.map { |l| URI.parse(l) }.find { |l| l.host && l.host[/(creativecommons.org|opensource.org)$/] }
    return nil unless uri.present?
    uri.scheme = "https"
    uri.host = Array(/(creativecommons.org|opensource.org)/.match uri.host).last
    if uri.host == "creativecommons.org"
      uri.path = uri.path.split('/')[0..-2].join("/") if uri.path.split('/').last == "legalcode"
      uri.path << '/' unless uri.path.end_with?('/')
    else
      uri.path = uri.path.gsub(/(-license|\.php|\.html)/, '')
      uri.path = uri.path.sub(/(mit|afl|apl|osl|gpl|ecl)/) { |match| match.upcase }
      uri.path = uri.path.sub(/(artistic|apache)/) { |match| match.titleize }
      uri.path = uri.path.sub(/([^0-9\-]+)(-)?([1-9])?(\.)?([0-9])?$/) do
        m = Regexp.last_match
        text = m[1]
        if m[3].present?
          version = [m[3], m[5].presence || "0"].join(".")
          [text, version].join("-")
        else
          text
        end
      end
    end
    uri.to_s
  rescue URI::InvalidURIError
    nil
  end
def normalize_license ( licenses ) uri = licenses . map { | l | URI . parse ( l ) } . find { | l | l . host && l . host [ / (creativecommons.org|opensource.org)$ / ] } return nil unless uri . present? uri . scheme = "https" uri . host = Array ( / (creativecommons.org|opensource.org) / . match uri . host ) . last if uri . host == "creativecommons.org" uri . path = uri . path . split ( '/' ) [ 0 .. - 2 ] . join ( "/" ) if uri . path . split ( '/' ) . last == "legalcode" uri . path << '/' unless uri . path . end_with? ( '/' ) else uri . path = uri . path . gsub ( / (-license| \. php| \. html) / , '' ) uri . path = uri . path . sub ( / (mit|afl|apl|osl|gpl|ecl) / ) { | match | match . upcase } uri . path = uri . path . sub ( / (artistic|apache) / ) { | match | match . titleize } uri . path = uri . path . sub ( / ([^0-9 \- ]+)(-)?([1-9])?( \. )?([0-9])?$ / ) do m = Regexp . last_match text = m [ 1 ] if m [ 3 ] . present? version = [ m [ 3 ] , m [ 5 ] . presence || "0" ] . join ( "." ) [ text , version ] . join ( "-" ) else text end end end uri . to_s rescue URI :: InvalidURIError nil end
find Creative Commons or OSI license in rightsURI array
find Creative Commons or OSI license in rightsURI array
# use HTTPS # use host name without subdomain # normalize URLs
licenses
<not_specific>