Class: Licensee::Rule

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

Overview

A single rule used to describe license conditions/permissions/limitations.

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

#serialize_hash_value, #to_h

Constructor Details

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

Returns a new instance of Rule.



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

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.



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

def description
  @description
end

#groupObject (readonly)

Returns the value of attribute group.



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

def group
  @group
end

#labelObject (readonly)

Returns the value of attribute label.



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

def label
  @label
end

#tagObject (readonly)

Returns the value of attribute tag.



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

def tag
  @tag
end

Class Method Details

.allObject



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

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



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

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



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

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

.groupsObject



51
52
53
# File 'lib/licensee/rule.rb', line 51

def groups
  Rule.raw_rules.keys
end

.raw_rulesObject



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

def raw_rules
  YAML.safe_load_file(Rule.file_path)
end

Instance Method Details

#inspectObject



19
20
21
# File 'lib/licensee/rule.rb', line 19

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