Sha256: 7a8ae64e8cb466d29b5c52afcb1502c8a7fc3b2452368a7f900ed6f070433a87

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

module Licensee
  class Rule
    attr_reader :tag, :label, :description, :group

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

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

    class << self
      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

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

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

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

      def groups
        Rule.raw_rules.keys
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
licensee-8.7.0 lib/licensee/rule.rb