Class: LicenseScout::License
- Inherits:
-
Object
- Object
- LicenseScout::License
- Defined in:
- lib/license_scout/license.rb
Defined Under Namespace
Classes: Record
Instance Attribute Summary collapse
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#records ⇒ Object
readonly
Returns the value of attribute records.
Instance Method Summary collapse
-
#add_license(license_id, source, contents_url, options) ⇒ void
Capture a license that was specified in metadata.
-
#initialize(path = nil) ⇒ License
constructor
A new instance of License.
-
#is_allowed? ⇒ Boolean
Whether or not the license(s) are allowed.
-
#is_flagged? ⇒ Boolean
Whether or not the license(s) are flagged.
-
#undetermined? ⇒ Boolean
Whether we were unable to determine a license.
Constructor Details
#initialize(path = nil) ⇒ License
Returns a new instance of License.
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
#project ⇒ Object (readonly)
Returns the value of attribute project.
46 47 48 |
# File 'lib/license_scout/license.rb', line 46 def project @project end |
#records ⇒ Object (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
79 80 81 82 |
# File 'lib/license_scout/license.rb', line 79 def add_license(license_id, source, contents_url, ) content = license_content(license_id, contents_url) @records.push(Record.new(license_id, source, content, )) end |
#is_allowed? ⇒ Boolean
Returns 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.
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.
95 96 97 |
# File 'lib/license_scout/license.rb', line 95 def undetermined? (records.map(&:parsed_expression).flatten.compact).empty? end |