Class: Licensee::Rule

Inherits:
Object
  • Object
show all
Includes:
HashHelper
Defined in:
lib/licensee/rule.rb

Constant Summary collapse

HASH_METHODS =
%i[tag label description].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from HashHelper

#to_h

Constructor Details

#initialize(tag: nil, label: nil, description: nil, group: nil) ⇒ Rule

Returns a new instance of Rule.



8
9
10
11
12
13
# File 'lib/licensee/rule.rb', line 8

def initialize(tag: nil, label: nil, description: nil, group: nil)
  @tag = tag
  @label = label
  @description = description
  @group = group
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



3
4
5
# File 'lib/licensee/rule.rb', line 3

def description
  @description
end

#groupObject (readonly)

Returns the value of attribute group.



3
4
5
# File 'lib/licensee/rule.rb', line 3

def group
  @group
end

#labelObject (readonly)

Returns the value of attribute label.



3
4
5
# File 'lib/licensee/rule.rb', line 3

def label
  @label
end

#tagObject (readonly)

Returns the value of attribute tag.



3
4
5
# File 'lib/licensee/rule.rb', line 3

def tag
  @tag
end

Class Method Details

.allObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/licensee/rule.rb', line 20

def all
  @all ||= raw_rules.map do |group, rules|
    rules.map do |rule|
      Rule.new(
        tag:         rule['tag'],
        label:       rule['label'],
        description: rule['description'],
        group:       group
      )
    end
  end.flatten
end

.file_pathObject



38
39
40
41
# File 'lib/licensee/rule.rb', line 38

def file_path
  dir = File.dirname(__FILE__)
  File.expand_path '../../vendor/choosealicense.com/_data/rules.yml', dir
end

.find_by_tag_and_group(tag, group = nil) ⇒ Object Also known as: find_by_tag



33
34
35
# File 'lib/licensee/rule.rb', line 33

def find_by_tag_and_group(tag, group = nil)
  Rule.all.find { |r| r.tag == tag && (group.nil? || r.group == group) }
end

.groupsObject



47
48
49
# File 'lib/licensee/rule.rb', line 47

def groups
  Rule.raw_rules.keys
end

.raw_rulesObject



43
44
45
# File 'lib/licensee/rule.rb', line 43

def raw_rules
  YAML.safe_load File.read(Rule.file_path)
end

Instance Method Details

#inspectObject



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

def inspect
  "#<Licensee::Rule @tag=\"#{tag}\">"
end