Class: Licensee::Rule

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Rule.



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

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



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/licensee/rule.rb', line 17

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



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

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

.find_by_tag(tag) ⇒ Object



30
31
32
# File 'lib/licensee/rule.rb', line 30

def find_by_tag(tag)
  Rule.all.find { |r| r.tag == tag }
end

.groupsObject



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

def groups
  Rule.raw_rules.keys
end

.raw_rulesObject



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

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

Instance Method Details

#inspectObject



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

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