Class: Bibliothecary::Parsers::CRAN
- Inherits:
-
Object
- Object
- Bibliothecary::Parsers::CRAN
- Defined in:
- lib/bibliothecary/parsers/cran.rb
Constant Summary collapse
- PLATFORM_NAME =
'cran'
- REQUIRE_REGEXP =
/([a-zA-Z0-9\-_\.]+)\s?\(?([><=\s\d\.,]+)?\)?/
Class Method Summary collapse
- .analyse(folder_path, file_list) ⇒ Object
- .analyse_description(folder_path, file_list) ⇒ Object
- .parse(filename, file_contents) ⇒ Object
- .parse_description(manifest) ⇒ Object
- .parse_section(manifest, name) ⇒ Object
Class Method Details
.analyse(folder_path, file_list) ⇒ Object
18 19 20 |
# File 'lib/bibliothecary/parsers/cran.rb', line 18 def self.analyse(folder_path, file_list) [analyse_description(folder_path, file_list)] end |
.analyse_description(folder_path, file_list) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/bibliothecary/parsers/cran.rb', line 22 def self.analyse_description(folder_path, file_list) path = file_list.find{|path| path.gsub(folder_path, '').gsub(/^\//, '').match(/^DESCRIPTION$/i) } return unless path manifest = DebControl::ControlFileBase.parse File.open(path).read { platform: PLATFORM_NAME, path: path, dependencies: parse_description(manifest) } end |
.parse(filename, file_contents) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/bibliothecary/parsers/cran.rb', line 9 def self.parse(filename, file_contents) if filename.match(/^DESCRIPTION$/i) control = DebControl::ControlFileBase.parse(file_contents) parse_description(control) else [] end end |
.parse_description(manifest) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/bibliothecary/parsers/cran.rb', line 35 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
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/bibliothecary/parsers/cran.rb', line 42 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 |