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.



10
11
12
13
14
15
# File 'lib/licensee/rule.rb', line 10

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.



5
6
7
# File 'lib/licensee/rule.rb', line 5

def description
  @description
end

#groupObject (readonly)

Returns the value of attribute group.



5
6
7
# File 'lib/licensee/rule.rb', line 5

def group
  @group
end

#labelObject (readonly)

Returns the value of attribute label.



5
6
7
# File 'lib/licensee/rule.rb', line 5

def label
  @label
end

#tagObject (readonly)

Returns the value of attribute tag.



5
6
7
# File 'lib/licensee/rule.rb', line 5

def tag
  @tag
end

Class Method Details

.allObject



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

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



40
41
42
43
# File 'lib/licensee/rule.rb', line 40

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



35
36
37
# File 'lib/licensee/rule.rb', line 35

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

.groupsObject



49
50
51
# File 'lib/licensee/rule.rb', line 49

def groups
  Rule.raw_rules.keys
end

.raw_rulesObject



45
46
47
# File 'lib/licensee/rule.rb', line 45

def raw_rules
  YAML.safe_load_file(Rule.file_path)
end

Instance Method Details

#inspectObject



17
18
19
# File 'lib/licensee/rule.rb', line 17

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