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

included

Class Method Details

.parse(filename, path) ⇒ Object



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

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

.parse_description(manifest) ⇒ Object



20
21
22
23
24
25
# File 'lib/bibliothecary/parsers/cran.rb', line 20

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

.parse_section(manifest, name) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/bibliothecary/parsers/cran.rb', line 27

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