class Licensee::LicenseField
Constants
- FIELD_REGEX
Public Class Methods
all()
click to toggle source
Returns an array of all known LicenseFields
# File lib/licensee/license_field.rb, line 21 def all @all ||= begin path = '../../vendor/choosealicense.com/_data/fields.yml' path = File.expand_path path, __dir__ fields = YAML.safe_load File.read(path) fields.map { |field| LicenseField.from_hash(field) } end end
find(key)
click to toggle source
Return a single license field
key - string representing the field’s text
Returns a LicenseField
# File lib/licensee/license_field.rb, line 11 def find(key) @all.find { |f| f.key == key } end
from_array(array)
click to toggle source
Given an array of keys, returns an array of coresponding LicenseFields
# File lib/licensee/license_field.rb, line 37 def from_array(array) array.map { |key| LicenseField.find(key) } end
from_content(content)
click to toggle source
Given a license body, returns an array of included LicneseFields
# File lib/licensee/license_field.rb, line 42 def from_content(content) return [] unless content LicenseField.from_array content.scan(FIELD_REGEX).flatten end
from_hash(hash)
click to toggle source
Builds a LicenseField
from a hash of properties
# File lib/licensee/license_field.rb, line 31 def from_hash(hash) ordered_array = hash.values_at(*members.map(&:to_s)) new(*ordered_array) end
keys()
click to toggle source
Returns an array of strings representing all field keys
# File lib/licensee/license_field.rb, line 16 def keys @keys ||= LicenseField.all.map(&:key) end
Public Instance Methods
label()
click to toggle source
The human-readable field name
# File lib/licensee/license_field.rb, line 53 def label key.sub('fullname', 'full name').capitalize end
Also aliased as: to_s
raw_text()
click to toggle source
# File lib/licensee/license_field.rb, line 58 def raw_text "[#{key}]" end