Sha256: 433f80c98b0c994e6ce32d34a2b354ffd3efc450aa4e10eaee085226c88b17b2

Contents?: true

Size: 795 Bytes

Versions: 8

Compression:

Stored size: 795 Bytes

Contents

# frozen_string_literal: true

module Spandx
  module Dotnet
    module Parsers
      class PackagesConfig < ::Spandx::Core::Parser
        def 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)
          ::Spandx::Core::Dependency.new(package_manager: :nuget, name: name, version: version)
        end

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

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
spandx-0.13.3 lib/spandx/dotnet/parsers/packages_config.rb
spandx-0.13.2 lib/spandx/dotnet/parsers/packages_config.rb
spandx-0.13.1 lib/spandx/dotnet/parsers/packages_config.rb
spandx-0.13.0 lib/spandx/dotnet/parsers/packages_config.rb
spandx-0.12.3 lib/spandx/dotnet/parsers/packages_config.rb
spandx-0.12.2 lib/spandx/dotnet/parsers/packages_config.rb
spandx-0.12.1 lib/spandx/dotnet/parsers/packages_config.rb
spandx-0.12.0 lib/spandx/dotnet/parsers/packages_config.rb