Class: DataKitten::License

Inherits:
Object
  • Object
show all
Defined in:
lib/data_kitten/license.rb

Overview

A license for a Dataset or Distribution

Constant Summary collapse

LICENSES =
{
  /opendatacommons.org.*\/by(\/|$)/ => "odc-by",
  /opendatacommons.org.*\/odbl(\/|$)/ => "odc-odbl",
  /opendatacommons.org.*\/pddl(\/|$)/ => "odc-pddl",
  /opendefinition.org.*\/odc-by(\/|$)/ => "odc-by",
  /opendefinition.org.*\/odc-pddl(\/|$)/ => "odc-pddl",
  /opendefinition.org.*\/cc-zero(\/|$)/ => "cc-zero",
  /opendefinition.org.*\/cc-by(\/|$)/ => "cc-by",
  /opendefinition.org.*\/cc-by-sa(\/|$)/ => "cc-by-sa",
  /opendefinition.org.*\/gfdl(\/|$)/ => "gfdl",
  /creativecommons.org.*\/zero(\/|$)/ => "cc-zero",
  /creativecommons.org.*\/by-sa(\/|$)/ => "cc-by-sa",
  /creativecommons.org.*\/by(\/|$)/ => "cc-by",
  /(data|nationalarchives).gov.uk.*\/open-government-licence(\/|$)/ => "ogl-uk",
  /usa.gov\/publicdomain(\/|$)/ => "us-pd"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ License

Create a new License object.

Parameters:

  • options (Hash)

    A set of options with which to initialise the license.

Options Hash (options):

  • :id (String)

    the short ID for the license

  • :name (String)

    the human name for the license

  • :uri (String)

    the URI of the license text

  • :type (String)

    the type of information covered by this license.



51
52
53
54
55
56
57
# File 'lib/data_kitten/license.rb', line 51

def initialize(options)
  @id = options[:id]
  @name = options[:name]
  @uri = options[:uri]
  @type = options[:type]
  @abbr = get_license_abbr(@uri) if @uri
end

Instance Attribute Details

#abbrString

Returns the license abbreviation.

Returns:

  • (String)

    the license abbreviation



42
43
44
# File 'lib/data_kitten/license.rb', line 42

def abbr
  @abbr
end

#idObject

Returns the value of attribute id.



26
27
28
# File 'lib/data_kitten/license.rb', line 26

def id
  @id
end

#isString

Returns a short ID that identifies the license.

Returns:

  • (String)

    a short ID that identifies the license.



26
# File 'lib/data_kitten/license.rb', line 26

attr_accessor :id

#nameString

Returns the human name of the license.

Returns:

  • (String)

    the human name of the license.



30
31
32
# File 'lib/data_kitten/license.rb', line 30

def name
  @name
end

#typeString

Returns the type of information this license applies to. Could be :data or :content.

Returns:

  • (String)

    the type of information this license applies to. Could be :data or :content.



38
39
40
# File 'lib/data_kitten/license.rb', line 38

def type
  @type
end

#uriString

Returns the URI for the license text.

Returns:

  • (String)

    the URI for the license text.



34
35
36
# File 'lib/data_kitten/license.rb', line 34

def uri
  @uri
end

Instance Method Details

#get_license_abbr(uri) ⇒ Object



59
60
61
62
# File 'lib/data_kitten/license.rb', line 59

def get_license_abbr(uri)
  license = LICENSES.find { |regex, abbr| uri =~ regex }
  license.last if license
end