Class: Bibliothecary::Parsers::CRAN
- Inherits:
-
Object
- Object
- Bibliothecary::Parsers::CRAN
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
.mapping ⇒ Object
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) ⇒ Object
19
20
21
22
23
24
25
|
# File 'lib/bibliothecary/parsers/cran.rb', line 19
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
|
.parse_section(manifest, name) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/bibliothecary/parsers/cran.rb', line 27
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
|