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
_inject_tags(package, _tags) click to toggle source
# File lib/upman/utils/parser.rb, line 6
def _inject_tags(package, _tags)
  _tags.each do |_tag|
    tag = Tag.where(label: _tag.label).first_or_create
    unless Package.joins(:tags).where('id' => package.id).exists?
      package.tags << tag
    end
  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_package_tags(body) click to toggle source

Parse something like Tag: game::strategy, interface::graphical, interface::x11, role::program,

uitoolkit::sdl, uitoolkit::wxwidgets, use::gameplaying,
x11::application
# File lib/upman/utils/parser.rb, line 73
def _parse_package_tags(body)
  result = []
  body.split("\n").each do |line|
    next unless line =~ /^Tag: ([a-z0-9:,\s\n]+)$/i

    Regexp.last_match(1).strip.split(',').each do |tag|
      result.push(Tag.new(label: tag.strip))
    end
  end
  result
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