Class: Licensee::License
Constant Summary
collapse
- YAML_DEFAULTS =
{
"featured" => false,
"hidden" => false,
"variant" => false
}
- HIDDEN_LICENSES =
%w[other no-license]
ContentHelper::DIGEST
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#content_normalized, #hash, #wordset
Constructor Details
#initialize(key) ⇒ License
Returns a new instance of License.
62
63
64
|
# File 'lib/licensee/license.rb', line 62
def initialize(key)
@key = key.downcase
end
|
Instance Attribute Details
#key ⇒ Object
Returns the value of attribute key.
50
51
52
|
# File 'lib/licensee/license.rb', line 50
def key
@key
end
|
Class Method Details
.all(options = {}) ⇒ Object
All license objects defined via Licensee (via choosealicense.com)
Options - :hidden - boolean, whether to return hidden licenses, defaults to false Options - :featured - boolean, whether to return only (non)featured licenses, defaults to all
Returns an Array of License objects.
16
17
18
19
20
21
|
# File 'lib/licensee/license.rb', line 16
def all(options={})
output = licenses.dup
output.reject! { |l| l.hidden? } unless options[:hidden]
output.select! { |l| l.featured? == options[:featured] } unless options[:featured].nil?
output
end
|
.find(key, options = {}) ⇒ Object
Also known as:
[], find_by_key
27
28
29
30
31
|
# File 'lib/licensee/license.rb', line 27
def find(key, options={})
options = {:hidden => true}.merge(options)
key = key.downcase
all(options).find { |license| license.key == key }
end
|
.keys ⇒ Object
23
24
25
|
# File 'lib/licensee/license.rb', line 23
def keys
@keys ||= license_files.map { |l| File.basename(l, ".txt").downcase } + ["other"]
end
|
.license_dir ⇒ Object
35
36
37
|
# File 'lib/licensee/license.rb', line 35
def license_dir
File.expand_path "../../vendor/choosealicense.com/_licenses", File.dirname(__FILE__)
end
|
.license_files ⇒ Object
39
40
41
|
# File 'lib/licensee/license.rb', line 39
def license_files
@license_files ||= Dir.glob("#{license_dir}/*.txt")
end
|
Instance Method Details
#==(other) ⇒ Object
122
123
124
|
# File 'lib/licensee/license.rb', line 122
def ==(other)
other != nil && key == other.key
end
|
#content ⇒ Object
Also known as:
to_s, text, body
The license body (e.g., contents - frontmatter)
107
108
109
|
# File 'lib/licensee/license.rb', line 107
def content
@content ||= parts[2] if parts && parts[2]
end
|
#featured? ⇒ Boolean
Also known as:
featured
96
97
98
|
# File 'lib/licensee/license.rb', line 96
def featured?
!!(meta["featured"] if meta)
end
|
#hidden? ⇒ Boolean
101
102
103
104
|
# File 'lib/licensee/license.rb', line 101
def hidden?
return true if HIDDEN_LICENSES.include?(key)
!!(meta["hidden"] if meta)
end
|
#inspect ⇒ Object
114
115
116
|
# File 'lib/licensee/license.rb', line 114
def inspect
"#<Licensee::License key=\"#{key}\" name=\"#{name}\">"
end
|
License metadata from YAML front matter
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/licensee/license.rb', line 72
def meta
@meta ||= if parts && parts[1]
if YAML.respond_to? :safe_load
meta = YAML.safe_load(parts[1])
else
meta = YAML.load(parts[1])
end
YAML_DEFAULTS.merge(meta)
end
end
|
#name ⇒ Object
Returns the human-readable license name
84
85
86
|
# File 'lib/licensee/license.rb', line 84
def name
meta.nil? ? key.capitalize : meta["title"]
end
|
#name_without_version ⇒ Object
92
93
94
|
# File 'lib/licensee/license.rb', line 92
def name_without_version
/(.+?)(( v?\d\.\d)|$)/.match(name)[1]
end
|
#nickname ⇒ Object
88
89
90
|
# File 'lib/licensee/license.rb', line 88
def nickname
meta["nickname"] if meta
end
|
#path ⇒ Object
Path to vendored license file on disk
67
68
69
|
# File 'lib/licensee/license.rb', line 67
def path
@path ||= File.expand_path "#{@key}.txt", Licensee::License.license_dir
end
|
#url ⇒ Object
118
119
120
|
# File 'lib/licensee/license.rb', line 118
def url
URI.join(Licensee::DOMAIN, "/licenses/#{key}/").to_s
end
|