Sha256: ad32e21aeb546cf6bf44d91c87e556a10a44a09599914fb1ba1172eb44a1bad7

Contents?: true

Size: 1.09 KB

Versions: 7

Compression:

Stored size: 1.09 KB

Contents

# frozen_string_literal: true

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

        def parse(file_path)
          project_paths_from(file_path).map do |path|
            ::Spandx::Core::Parser
              .for(path, catalogue: catalogue)
              .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

7 entries across 7 versions & 1 rubygems

Version Path
spandx-0.11.0 lib/spandx/dotnet/parsers/sln.rb
spandx-0.10.1 lib/spandx/dotnet/parsers/sln.rb
spandx-0.10.0 lib/spandx/dotnet/parsers/sln.rb
spandx-0.9.0 lib/spandx/dotnet/parsers/sln.rb
spandx-0.8.0 lib/spandx/dotnet/parsers/sln.rb
spandx-0.7.0 lib/spandx/dotnet/parsers/sln.rb
spandx-0.6.0 lib/spandx/dotnet/parsers/sln.rb