Class: Licensee::License
- Inherits:
-
Object
- Object
- Licensee::License
- Defined in:
- lib/licensee/license.rb
Instance Attribute Summary collapse
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Class Method Summary collapse
Instance Method Summary collapse
-
#body ⇒ Object
(also: #to_s, #text)
The license body (e.g., contents - frontmatter).
-
#body_normalized ⇒ Object
License body with all whitespace replaced with a single space.
-
#content ⇒ Object
Raw content of license file, including YAML front matter.
- #featured? ⇒ Boolean (also: #featured)
-
#hashsig ⇒ Object
Git-computed hash signature for the license file.
-
#initialize(key) ⇒ License
constructor
A new instance of License.
- #inspect ⇒ Object
-
#meta ⇒ Object
License metadata from YAML front matter.
-
#name ⇒ Object
Returns the human-readable license name.
-
#path ⇒ Object
Path to vendored license file on disk.
- #url ⇒ Object
Constructor Details
#initialize(key) ⇒ License
Returns a new instance of License.
11 12 13 |
# File 'lib/licensee/license.rb', line 11 def initialize(key) @key=key.downcase end |
Instance Attribute Details
#key ⇒ Object (readonly)
Returns the value of attribute key.
9 10 11 |
# File 'lib/licensee/license.rb', line 9 def key @key end |
Class Method Details
Instance Method Details
#body ⇒ Object Also known as: to_s, text
The license body (e.g., contents - frontmatter)
47 48 49 |
# File 'lib/licensee/license.rb', line 47 def body @body ||= parts[2] if parts && parts[2] end |
#body_normalized ⇒ Object
License body with all whitespace replaced with a single space
54 55 56 |
# File 'lib/licensee/license.rb', line 54 def body_normalized @content_normalized ||= body.to_s.downcase.gsub(/\s+/, " ").strip end |
#content ⇒ Object
Raw content of license file, including YAML front matter
21 22 23 24 25 26 27 28 29 |
# File 'lib/licensee/license.rb', line 21 def content @content ||= if File.exists?(path) File.open(path).read elsif key == "other" # A pseudo-license with no content nil else raise Licensee::InvalidLicense, "'#{key}' is not a valid license key" end end |
#featured? ⇒ Boolean Also known as: featured
41 42 43 |
# File 'lib/licensee/license.rb', line 41 def featured? !!(["featured"] if ) end |
#hashsig ⇒ Object
Git-computed hash signature for the license file
59 60 61 62 63 64 |
# File 'lib/licensee/license.rb', line 59 def hashsig @hashsig ||= Rugged::Blob::HashSignature.new( body, Rugged::Blob::HashSignature::WHITESPACE_SMART) rescue Rugged::InvalidError nil end |
#inspect ⇒ Object
66 67 68 |
# File 'lib/licensee/license.rb', line 66 def inspect "#<Licensee::License key=\"#{key}\" name=\"#{name}\">" end |
#meta ⇒ Object
License metadata from YAML front matter
32 33 34 |
# File 'lib/licensee/license.rb', line 32 def @meta ||= YAML.load(parts[1]) if parts && parts[1] end |
#name ⇒ Object
Returns the human-readable license name
37 38 39 |
# File 'lib/licensee/license.rb', line 37 def name .nil? ? key.capitalize : ["title"] end |