Class: LicenseScout::License

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

Defined Under Namespace

Classes: Record

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = nil) ⇒ License

Returns a new instance of License.

Parameters:

  • path (String, nil) (defaults to: nil)

    A path to give to Licensee to search for the license. Could be local path or GitHub URL.


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/license_scout/license.rb', line 50

def initialize(path = nil)
  if path.nil?
    @project = nil
    @records = []
  else
    @project = Licensee.project(path, detect_readme: true)
    @records = []

    project.licenses.each_index do |i|
      record = Record.new(
        project.licenses[i].spdx_id,
        project.matched_files[i].filename,
        project.matched_files[i].content
      )

      # Favor records that have identified a license
      record.id.nil? ? @records.push(record) : @records.unshift(record)
    end
  end
end

Instance Attribute Details

#projectObject (readonly)

Returns the value of attribute project.


46
47
48
# File 'lib/license_scout/license.rb', line 46

def project
  @project
end

#recordsObject (readonly)

Returns the value of attribute records.


47
48
49
# File 'lib/license_scout/license.rb', line 47

def records
  @records
end

Instance Method Details

#add_license(license_id, source, contents_url, options) ⇒ void

This method returns an undefined value.

Capture a license that was specified in metadata

Parameters:

  • license_id (String)

    The license as specified in the metadata file

  • source (String)

    Where we found the license info

  • contents_url (String)

    Where we can find the contents of the license

  • options (Hash)

    Options to control various behavior


79
80
81
82
# File 'lib/license_scout/license.rb', line 79

def add_license(license_id, source, contents_url, options)
  content = license_content(license_id, contents_url)
  @records.push(Record.new(license_id, source, content, options))
end

#is_allowed?Boolean

Returns Whether or not the license(s) are allowed.

Returns:

  • (Boolean)

    Whether or not the license(s) are allowed


85
86
87
# File 'lib/license_scout/license.rb', line 85

def is_allowed?
  (records.map(&:parsed_expression).flatten.compact & LicenseScout::Config.allowed_licenses).any?
end

#is_flagged?Boolean

Returns Whether or not the license(s) are flagged.

Returns:

  • (Boolean)

    Whether or not the license(s) are flagged


90
91
92
# File 'lib/license_scout/license.rb', line 90

def is_flagged?
  (records.map(&:parsed_expression).flatten.compact & LicenseScout::Config.flagged_licenses).any?
end

#undetermined?Boolean

Returns Whether we were unable to determine a license.

Returns:

  • (Boolean)

    Whether we were unable to determine a license


95
96
97
# File 'lib/license_scout/license.rb', line 95

def undetermined?
  (records.map(&:parsed_expression).flatten.compact).empty?
end