Sha256: b3e0b72409bda99f06fbf0ba8f805e7e9f94b9481cf1e782748a9e05bd5c1463

Contents?: true

Size: 1.5 KB

Versions: 16

Compression:

Stored size: 1.5 KB

Contents

require 'deb_control'

module Bibliothecary
  module Parsers
    class CRAN
      PLATFORM_NAME = 'cran'
      REQUIRE_REGEXP = /([a-zA-Z0-9\-_\.]+)\s?\(?([><=\s\d\.,]+)?\)?/

      def self.parse(filename, file_contents)
        if filename.match(/^DESCRIPTION$/i)
          control = DebControl::ControlFileBase.parse(file_contents)
          parse_description(control)
        else
          []
        end
      end

      def self.analyse(folder_path, file_list)
        [analyse_description(folder_path, file_list)]
      end

      def self.analyse_description(folder_path, file_list)
        path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^DESCRIPTION$/i) }
        return unless path

        manifest = DebControl::ControlFileBase.parse File.open(path).read

        {
          platform: PLATFORM_NAME,
          path: path,
          dependencies: parse_description(manifest)
        }
      end

      def self.parse_description(manifest)
        parse_section(manifest, 'Depends') +
        parse_section(manifest, 'Imports') +
        parse_section(manifest, 'Suggests') +
        parse_section(manifest, 'Enhances')
      end

      def self.parse_section(manifest, name)
        deps = manifest.first[name].gsub("\n", '').split(',').map(&:strip)
        deps.map do |dependency|
          dep = dependency.match(REQUIRE_REGEXP)
          {
            name: dep[1],
            version: dep[2] || '*',
            type: name.downcase
          }
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
bibliothecary-1.2.1 lib/bibliothecary/parsers/cran.rb
bibliothecary-1.2.0 lib/bibliothecary/parsers/cran.rb
bibliothecary-1.1.0 lib/bibliothecary/parsers/cran.rb
bibliothecary-1.0.0 lib/bibliothecary/parsers/cran.rb
bibliothecary-0.16.1 lib/bibliothecary/parsers/cran.rb
bibliothecary-0.16.0 lib/bibliothecary/parsers/cran.rb
bibliothecary-0.15.2 lib/bibliothecary/parsers/cran.rb
bibliothecary-0.15.1 lib/bibliothecary/parsers/cran.rb
bibliothecary-0.15.0 lib/bibliothecary/parsers/cran.rb
bibliothecary-0.14.1 lib/bibliothecary/parsers/cran.rb
bibliothecary-0.14.0 lib/bibliothecary/parsers/cran.rb
bibliothecary-0.13.1 lib/bibliothecary/parsers/cran.rb
bibliothecary-0.13.0 lib/bibliothecary/parsers/cran.rb
bibliothecary-0.12.0 lib/bibliothecary/parsers/cran.rb
bibliothecary-0.11.0 lib/bibliothecary/parsers/cran.rb
bibliothecary-0.10.0 lib/bibliothecary/parsers/cran.rb