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



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

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

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



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

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

.parse_section(manifest, name, source = nil) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/bibliothecary/parsers/cran.rb', line 33

def self.parse_section(manifest, name, source = nil)
  return [] unless manifest.first[name]

  deps = manifest.first[name].delete("\n").split(",").map(&:strip)
  deps.map do |dependency|
    dep = dependency.match(REQUIRE_REGEXP)
    Dependency.new(
      name: dep[1],
      requirement: dep[2],
      type: name.downcase,
      source: source
    )
  end
end