Parse package from the info file

This commit is contained in:
Eugen Wissner 2023-05-23 20:36:19 +02:00
parent f564676cb6
commit 341eafcbf2
Signed by: belka
GPG Key ID: A27FDC1E8EE902C0

View File

@ -21,6 +21,32 @@ class Package
def name_version
"#{name}-#{@version}"
end
def self.parse(path, info_contents)
current_line = String.new ''
variables = {}
info_contents.each_line(chomp: true) do |file_line|
current_line << file_line.delete_suffix('\\')
next if file_line.end_with? '\\'
variables.store(*parse_pair(current_line))
current_line.clear
end
from_hash path, variables
end
private_class_method def self.parse_pair(current_line)
variable_name, variable_value = current_line.split '='
[variable_name, variable_value[1...-1].split]
end
private_class_method def self.from_hash(path, variables)
Package.new path,
version: variables['VERSION'].join,
homepage: variables['HOMEPAGE'].join,
requires: variables['REQUIRES']
end
end
class Download