Sha256: a720bd89e4eb629f4925a8bdf783194ddc40543017cf670250134396da2b554d

Contents?: true

Size: 1.07 KB

Versions: 8

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module Spandx
  module Dotnet
    module Parsers
      class Sln < ::Spandx::Core::Parser
        def matches?(filename)
          filename.match?(/.*\.sln/)
        end

        def parse(file_path)
          project_paths_from(file_path).map do |path|
            ::Spandx::Core::Parser
              .for(path)
              .parse(path)
          end.flatten
        end

        private

        def project_paths_from(file_path)
          IO.readlines(file_path).map do |line|
            next unless project_line?(line)

            path = project_path_from(line)
            next unless path

            path = File.join(File.dirname(file_path), path)
            Pathname.new(path).cleanpath.to_path
          end.compact
        end

        def project_line?(line)
          line.match?(/^\s*Project\(/)
        end

        def project_path_from(line)
          path = line.split('"')[5]
          return unless path

          path = path.tr('\\', '/')
          path.match?(/\.[a-z]{2}proj$/) ? path : nil
        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/sln.rb
spandx-0.13.2 lib/spandx/dotnet/parsers/sln.rb
spandx-0.13.1 lib/spandx/dotnet/parsers/sln.rb
spandx-0.13.0 lib/spandx/dotnet/parsers/sln.rb
spandx-0.12.3 lib/spandx/dotnet/parsers/sln.rb
spandx-0.12.2 lib/spandx/dotnet/parsers/sln.rb
spandx-0.12.1 lib/spandx/dotnet/parsers/sln.rb
spandx-0.12.0 lib/spandx/dotnet/parsers/sln.rb