Sha256: ab0b649876df6c501dc2ee3d074da14f70219f3c8a628ae950668cfddc61d7f1

Contents?: true

Size: 1.25 KB

Versions: 11

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

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

    include Licensee::HashHelper
    HASH_METHODS = %i[tag label description].freeze

    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_and_group(tag, group = nil)
        Rule.all.find { |r| r.tag == tag && (group.nil? || r.group == group) }
      end
      alias find_by_tag find_by_tag_and_group

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

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

      def groups
        Rule.raw_rules.keys
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
licensee-9.16.0 lib/licensee/rule.rb
licensee-9.15.3 lib/licensee/rule.rb
licensee-9.15.2 lib/licensee/rule.rb
licensee-9.15.1 lib/licensee/rule.rb
licensee-9.15.0 lib/licensee/rule.rb
licensee-9.14.1 lib/licensee/rule.rb
licensee-9.14.0 lib/licensee/rule.rb
licensee-9.13.2 lib/licensee/rule.rb
licensee-9.13.1 lib/licensee/rule.rb
licensee-9.13.0 lib/licensee/rule.rb
licensee-9.12.0 lib/licensee/rule.rb