6 PREFIX_RE = /(>=|<=|<|>|=)/
7 CATEGORY_RE = /\w+-\w+/
9 VERSION_RE = /(\d+(\.\d+)*)+/
10 VERSION_EXT_RE = /[a-z]?(_(alpha|beta|pre|rc|p)\d+)?/
11 PACKAGE_NAME_RE = /[a-zA-Z0-9_-]+/
13 attr_reader :package_name, :version, :version_ext,
14 :prefix, :prefix_ext, :postfix, :origin,
17 # if convert is true, use GGem.ebuild_name() to convert the name
18 def initialize(str, convert = true)
20 str = GGem.ebuild_name(str) if convert == true
22 @prefix_ext, str = $&, $' if /^#{PREFIX_EXT_RE}/ === str
23 @prefix, str = $&, $' if /^#{PREFIX_RE}/ === str
24 @category, str = $1, $' if /^(#{CATEGORY_RE})\// === str
25 @postfix, str = $&, $` if /#{POSTFIX_RE}$/ === str
26 @version, @version_ext, str = $1, $3, $` if /-#{VERSION_RE}(#{VERSION_EXT_RE})/ === str
27 raise "Invalid atom: #{@origin}" unless /^#{PACKAGE_NAME_RE}$/ === str
32 alias_method :name, :package_name
33 attr_accessor :category
36 @category or Portage.category
40 # FIXME: support other gentoo atom prefixes
43 return Gem::Version::Requirement.default unless version
44 full_prefix = "#{prefix_ext}#{prefix}"
45 gem_prefix = if /^(~>|>|>=|=|!=|<=|<)$/ === full_prefix
50 Gem::Version::Requirement.create(["#{gem_prefix} #{version}"])
54 Gem::Dependency.new(package_name, [gem_requirement.to_s])
58 "#{prefix_ext}#{(prefix or "=") if version}#{category+"/" if category}#{package_name}"+
59 "#{"-"+version+version_ext if version}#{postfix}"
64 if str =~ /(.*\/)?(\S+)\.gem$/ # From gem file
66 atom.instance_eval { @origin = str }
73 alias_method :parse, :from_s
76 list.map { |str| parse(str) }
79 def from_gem_dependency(dep, category)
82 dep = Gem::Dependency.new(dep[0], dep[1])
84 prefix, version = *dep.version_requirements.instance_eval { @requirements.first }
85 new("#{prefix}#{category}/#{dep.name}-#{version}")
88 def from_required_ruby_version(spec)
89 spec.required_ruby_version.instance_eval do
90 if @requirements != nil
91 prefix, version = @requirements.first
92 "#{prefix}dev-lang/ruby-#{version}"
99 end # class DependencyAtom