Sha256: 7062bde65bf2829117fe6381939b686741ad7fb72161e20fec72df73dd5038d9

Contents?: true

Size: 1000 Bytes

Versions: 3

Compression:

Stored size: 1000 Bytes

Contents

require 'deb_control'

module Bibliothecary
  module Parsers
    class CRAN
      include Bibliothecary::Analyser

      REQUIRE_REGEXP = /([a-zA-Z0-9\-_\.]+)\s?\(?([><=\s\d\.,]+)?\)?/

      def self.mapping
        {
          /^DESCRIPTION$/i => :parse_description
        }
      end

      def self.parse_description(file_contents)
        manifest = DebControl::ControlFileBase.parse(file_contents)
        parse_section(manifest, 'Depends') +
        parse_section(manifest, 'Imports') +
        parse_section(manifest, 'Suggests') +
        parse_section(manifest, 'Enhances')
      end

      def self.parse_section(manifest, name)
        return [] unless manifest.first[name]
        deps = manifest.first[name].delete("\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

3 entries across 3 versions & 1 rubygems

Version Path
bibliothecary-5.0.2 lib/bibliothecary/parsers/cran.rb
bibliothecary-5.0.1 lib/bibliothecary/parsers/cran.rb
bibliothecary-5.0.0 lib/bibliothecary/parsers/cran.rb