Sha256: 414bdb0aaf0d9f1a6be4a4de3f7c6de09db66326b29da8de767d1c083dabf660

Contents?: true

Size: 1.07 KB

Versions: 10

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module Spandx
  module Os
    module Parsers
      class Apk < ::Spandx::Core::Parser
        def match?(path)
          path.basename.fnmatch?('installed')
        end

        def parse(lockfile)
          path = lockfile.to_s

          [].tap do |items|
            lockfile.open(mode: 'r') do |io|
              each_package(io) do |data|
                items.push(map_from(data, path))
              end
            end
          end
        end

        private

        def each_package(io)
          package = {}

          until io.eof?
            line = io.readline.chomp
            if line.empty?
              yield package

              package = {}
            else
              line.split(':').tap { |(key, value)| package[key] = value }
            end
          end
        end

        def map_from(data, path)
          ::Spandx::Core::Dependency.new(
            path: path,
            name: data['P'],
            version: data['V'],
            meta: data.merge('license' => [data['L']])
          )
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
spandx-0.18.3 lib/spandx/os/parsers/apk.rb
spandx-0.18.2 lib/spandx/os/parsers/apk.rb
spandx-0.18.1 lib/spandx/os/parsers/apk.rb
spandx-0.18.0 lib/spandx/os/parsers/apk.rb
spandx-0.17.0 lib/spandx/os/parsers/apk.rb
spandx-0.16.1 lib/spandx/os/parsers/apk.rb
spandx-0.16.0 lib/spandx/os/parsers/apk.rb
spandx-0.15.1 lib/spandx/os/parsers/apk.rb
spandx-0.15.0 lib/spandx/os/parsers/apk.rb
spandx-0.14.0 lib/spandx/os/parsers/apk.rb