Sha256: 3c62fb1c34096f88e44e11134ce40e9816510810dbb32d48d42f99bc7a04101f

Contents?: true

Size: 1 KB

Versions: 2

Compression:

Stored size: 1 KB

Contents

require 'deb_control'

module Bibliothecary
  module Parsers
    class CRAN
      include Bibliothecary::Analyser

      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.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

2 entries across 2 versions & 1 rubygems

Version Path
bibliothecary-2.0.1 lib/bibliothecary/parsers/cran.rb
bibliothecary-2.0.0 lib/bibliothecary/parsers/cran.rb