module Upman::Utils::Parser
Private Instance Methods
_get_hashed_values(body)
click to toggle source
# File lib/upman/utils/parser.rb, line 41 def _get_hashed_values(body) result = {} body.scan(/([\w-]+): (.+)/).each do |match| key = match[0].downcase.tr('-', '_') result[key] = match[1] end result end
_get_hashed_values_simple(body)
click to toggle source
# File lib/upman/utils/parser.rb, line 50 def _get_hashed_values_simple(body) result = {} body.each_line do |line| p line.split(':', 2) end result end
_inject_maintainer(package, _maintainer)
click to toggle source
# File lib/upman/utils/parser.rb, line 16 def _inject_maintainer(package, _maintainer) maintainer = Maintainer.where(name: _maintainer.name, email: _maintainer.email).first_or_create unless Package.joins(:maintainers).where('id' => package.id).exists? package.maintainers << maintainer end package end
_parse_package_maintainer(body)
click to toggle source
Parse something like Maintainer: Debian Games Team <pkg-games-devel@lists.alioth.debian.org>
# File lib/upman/utils/parser.rb, line 60 def _parse_package_maintainer(body) body.split("\n").each do |line| if line =~ /^Maintainer: (.*) <(.*)>$/i return Maintainer.new(name: Regexp.last_match(1), email: Regexp.last_match(2)) end end nil end
_parse_regex_group(body, regex)
click to toggle source
# File lib/upman/utils/parser.rb, line 34 def _parse_regex_group(body, regex) body.split("\n").each do |line| return Regexp.last_match(1) if line =~ regex end nil end
_parse_release_file(body)
click to toggle source
# File lib/upman/utils/parser.rb, line 24 def _parse_release_file(body) release_data = _get_hashed_values(body) release_data['architectures'] = release_data['architectures'].gsub(/\s+/m, ' ').strip.split(' ') if release_data['components'].present? release_data['components'] = release_data['components'].gsub(/\s+/m, ' ').strip.split(' ') end release_data['date'] = DateTime.parse(release_data['date']) release_data end