Class: Factorix::API::License

Inherits:
Data
  • Object
show all
Defined in:
lib/factorix/api/license.rb,
lib/factorix/api/license.rb,
sig/factorix/api/license.rbs

Overview

License object from MOD Portal API

Represents a MOD license information. Uses flyweight pattern for standard licenses. Also provides valid license identifiers for edit_details API.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, name:, title:, description:, url:) ⇒ License

Returns new License instance.

Parameters:

  • id (String) —

    license ID

  • name (String) —

    license name

  • title (String) —

    license title

  • description (String) —

    license description

  • url (String) —

    license URL

  • id: (String)
  • name: (String)
  • title: (String)
  • description: (String)
  • url: (String)


121
122
123
124
# File 'lib/factorix/api/license.rb', line 121

def initialize(id:, name:, title:, description:, url:)
  url = URI(url)
  super
end

Instance Attribute Details

#description ⇒ String (readonly)

Returns license description (long text).

Returns:

  • (String) —

    license description (long text)



18
19
20
# File 'lib/factorix/api/license.rb', line 18

def description
  @description
end

#id ⇒ String (readonly)

Returns license ID.

Returns:

  • (String) —

    license ID



18
19
20
# File 'lib/factorix/api/license.rb', line 18

def id
  @id
end

#name ⇒ String (readonly)

Returns license name.

Returns:

  • (String) —

    license name



18
19
20
# File 'lib/factorix/api/license.rb', line 18

def name
  @name
end

#title ⇒ String (readonly)

Returns license title.

Returns:

  • (String) —

    license title



18
19
20
# File 'lib/factorix/api/license.rb', line 18

def title
  @title
end

#url ⇒ URI::HTTPS (readonly)

Returns license URL.

Returns:

  • (URI::HTTPS) —

    license URL



18
19
20
# File 'lib/factorix/api/license.rb', line 18

def url
  @url
end

Class Method Details

.for(id) ⇒ License

Get License instance for the given identifier

Returns predefined instance for known licenses (flyweight pattern). Raises an error for unknown license identifiers.

Parameters:

  • id (String) —

    license identifier

Returns:

Raises:

  • (KeyError) —

    if license identifier is unknown



105
# File 'lib/factorix/api/license.rb', line 105

def self.for(id) = LICENSES.fetch(id.to_s)

.identifiers ⇒ Array<String>

Returns all license identifiers.

Returns:

  • (Array<String>) —

    all license identifiers



95
# File 'lib/factorix/api/license.rb', line 95

def self.identifiers = LICENSES.keys

.valid_identifier?(value) ⇒ Boolean

Check if the given value is a valid license identifier

Parameters:

  • value (String) —

    license identifier

Returns:

  • (Boolean) —

    true if valid (standard or custom license)



111
112
113
# File 'lib/factorix/api/license.rb', line 111

def self.valid_identifier?(value)
  LICENSES.key?(value) || CUSTOM_LICENSE_PATTERN.match?(value)
end