Sha256: 5619e6ef0bc24d6a999b87b8db70e7a46151f8036d2b7856d0a69630ae20d342

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

class Licensee
  class Licenses
    class << self

      # Returns an array of Licensee::License instances
      def list
        @licenses ||= begin
          licenses = []
          keys.each { |key| licenses.push License.new(key) }
          licenses
        end
      end

      def sorted_list
        list.sort { |a,b| a.name <=> b.name }.
        partition { |license| license.featured? }.
        flatten
      end

      # Given a license key, attempt to return a matching Licensee::License instance
      def find(key)
        list.find { |l| l.key.downcase == key.downcase }
      end
      alias_method :[], :find

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

      private

      # Returns a list of potential license keys, as vendored
      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

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
licensee-4.0.1 lib/licensee/licenses.rb