Class: Licensee::Licenses

Inherits:
Object
  • Object
show all
Defined in:
lib/licensee/licenses.rb

Class Method Summary collapse

Class Method Details

.baseObject

Path to vendored licenses



21
22
23
# File 'lib/licensee/licenses.rb', line 21

def base
  @base ||= File.expand_path "../../vendor/choosealicense.com/_licenses", File.dirname(__FILE__)
end

.find(key) ⇒ Object Also known as: []

Given a license key, attempt to return a matching Licensee::License instance



15
16
17
# File 'lib/licensee/licenses.rb', line 15

def find(key)
  list.find { |l| l.key.downcase == key.downcase }
end

.keysObject

Returns a list of potential license keys, as vendored



26
27
28
29
30
31
32
33
# File 'lib/licensee/licenses.rb', line 26

def keys
  @keys ||= begin
    keyes = Dir.entries(base)
    keyes.map! { |l| File.basename(l, ".txt").downcase }
    keyes.reject! { |l| l =~ /^\./ || l.nil? }
    keyes
  end
end

.listObject

Returns an array of Licensee::License instances



6
7
8
9
10
11
12
# File 'lib/licensee/licenses.rb', line 6

def list
  @licenses ||= begin
    licenses = []
    keys.each { |key| licenses.push License.new(key) }
    licenses
  end
end