Sha256: 667f028ade34b40aa4f6cb96257ca6eb869bc660c2b25ce5d2dfa17a7932cd0d

Contents?: true

Size: 853 Bytes

Versions: 2

Compression:

Stored size: 853 Bytes

Contents

# frozen_string_literal: true

module Spandx
  module Parsers
    class PackagesConfig < Base
      def self.matches?(filename)
        filename.match?(/packages\.config/)
      end

      def parse(lockfile)
        Nokogiri::XML(IO.read(lockfile))
          .search('//package')
          .map { |node| map_from(node) }
      end

      private

      def map_from(node)
        name = attribute_for('id', node)
        version = attribute_for('version', node)
        Dependency.new(
          name: name,
          version: version,
          licenses: nuget.licenses_for(name, version).map { |x| catalogue[x] }
        )
      end

      def attribute_for(key, node)
        node.attribute(key)&.value&.strip || node.at_xpath("./#{key}")&.content&.strip
      end

      def nuget
        @nuget ||= Gateways::Nuget.new
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spandx-0.1.5 lib/spandx/parsers/packages_config.rb
spandx-0.1.4 lib/spandx/parsers/packages_config.rb