Class: Bibliothecary::Parsers::CRAN

Inherits:
Object
  • Object
show all
Includes:
Analyser
Defined in:
lib/bibliothecary/parsers/cran.rb

Constant Summary collapse

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

Class Method Summary collapse

Methods included from Analyser

create_analysis, create_error_analysis, included

Class Method Details

.mappingObject



10
11
12
13
14
15
16
17
# File 'lib/bibliothecary/parsers/cran.rb', line 10

def self.mapping
  {
    match_filename("DESCRIPTION", case_insensitive: true) => {
      kind: 'manifest',
      parser: :parse_description
    }
  }
end

.parse_description(file_contents, options: {}) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/bibliothecary/parsers/cran.rb', line 23

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

.parse_section(manifest, name) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/bibliothecary/parsers/cran.rb', line 31

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],
      requirement: dep[2] || '*',
      type: name.downcase
    }
  end
end