Sha256: c42bb3ffe33b91c9ba769aa96519ed41410368960725d71fc60e226eb8264436

Contents?: true

Size: 1.91 KB

Versions: 5

Compression:

Stored size: 1.91 KB

Contents

module LicenseFinder
  class Dependency

    attr_reader :name, :version, :license, :approved, :license_url, :notes, :license_files, :readme_files

    def self.from_hash(attrs)
      lfs = attrs['license_files'] ? attrs['license_files'].map { |lf| lf['path'] } : []
      rfs = attrs['readme_files'] ? attrs['readme_files'].map { |rf| rf['path'] } : []
      new(attrs['name'], attrs['version'], attrs['license'], attrs['approved'], attrs['license_url'], attrs['notes'], lfs, rfs)
    end

    def initialize(name, version, license, approved, license_url = '', notes = '', license_files = [], readme_files = [])
      @name = name
      @version = version
      @license = license
      @approved = approved
      @license_url = license_url
      @notes = notes
      @license_files = license_files
      @readme_files = readme_files
    end

    def to_yaml_entry
      attrs = "- name: \"#{name}\"\n  version: \"#{version}\"\n  license: \"#{license}\"\n  approved: #{approved}\n  license_url: \"#{license_url}\"\n  notes: \"#{notes}\"\n"
      attrs << "  license_files:\n"
      if !self.license_files.empty?
        self.license_files.each do |lf|
          attrs << "  - path: \"#{lf}\"\n"
        end
      end
      attrs << "  readme_files:\n"
      if !self.readme_files.empty?
        self.readme_files.each do |rf|
          attrs << "  - path: \"#{rf}\"\n"
        end
      end
      attrs
    end

    def to_s
      url = ", #{license_url}" if license_url != ''
      str = "#{name} #{version}, #{license}#{url}"
      if license == 'other'
        str << "\n  license files:"
        unless self.license_files.empty?
          self.license_files.each do |lf|
            str << "\n    #{lf}"
          end
        end
        str << "\n  readme files:"
        unless self.readme_files.empty?
          self.readme_files.each do |lf|
            str << "\n    #{lf}"
          end
        end
      end

      str
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
license_finder-0.4.1 lib/license_finder/dependency.rb
license_finder-0.4.0 lib/license_finder/dependency.rb
license_finder-0.3.0 lib/license_finder/dependency.rb
license_finder-0.2.0 lib/license_finder/dependency.rb
license_finder-0.1.0 lib/license_finder/dependency.rb