class Archlinux::Query

Attributes

name[RW]
op[RW]
op2[RW]
version[RW]
version2[RW]

Public Class Methods

create(v) click to toggle source
# File lib/aur/versions.rb, line 87
def self.create(v)
        v.is_a?(self) ? v : self.new(v)
end
new(query) click to toggle source
# File lib/aur/versions.rb, line 97
def initialize(query)
        @query=query
        @name, @op, version, @op2, version2=parse(query)
        @version=Version.new(version)
        @version2=Version.new(version2)
end
strip(query) click to toggle source
# File lib/aur/versions.rb, line 91
def self.strip(query)
        self.create(query).name
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/aur/versions.rb, line 136
def <=>(other)
        other=self.class.create(other)
        min, strict=self.min
        omin, ostrict=other.min
        return 1 if min==omin and strict
        return -1 if min==omin and ostrict
        min <=> omin
end
max() click to toggle source
# File lib/aur/versions.rb, line 108
def max
        strict=false
        if @op=='<=' or @op=='='
                max=@version
        elsif @op=="<"
                max=@version; strict=true
        elsif @op2=="<="
                max=@version2
        elsif @op2=="<"
                max=@version2; strict=true
        end
        return max, strict #nil means Float::INFINITY, ie no restriction
end
min() click to toggle source
# File lib/aur/versions.rb, line 122
def min
        strict=false
        if @op=='>=' or @op=='='
                min=@version
        elsif @op==">"
                min=@version; strict=true
        elsif @op2==">="
                min=@version2
        elsif @op2==">"
                min=@version2; strict=true
        end
        return min, strict
end
satisfy?(other) click to toggle source

here we check if a package can satisfy a query note that other can itself be a query, think of a package that requires foo>=2.0 and bar which provides foo>=3 satisfy? is symmetric, it means that the intersection of the available version ranges is non empty

# File lib/aur/versions.rb, line 150
def satisfy?(other)
        case other
        when Version
                omin=other; omax=other; ominstrict=false; omaxstrict=false
                oname=@name #we assume the name comparison was already done
        else
                other=self.class.create(other)
                omax, omaxstrict=other.max
                omin, ominstrict=other.min
                oname=other.name
        end
        return false unless @name==oname
        min, strict=self.min
        return false if omax and min and (omax < min or omax == min && (strict or omaxstrict))
        max, strict=self.max
        return false if max and omin and (omin > max or omin == max && (strict or ominstrict))
        true
end
to_s() click to toggle source
# File lib/aur/versions.rb, line 104
def to_s
        @query
end

Private Instance Methods

parse(query) click to toggle source
# File lib/aur/versions.rb, line 169
        def parse(query)
        if (m=query.match(/^([^><=]*)([><=]*)([\w.\-+:]*)([><=]*)([\w.\-+:]*)$/))
                name=m[1]
                op=m[2]
                version=m[3]
                op2=m[4]
                version2=m[5]
                if op.nil?
                        name, version=Utils.rsplit(name, '-', 2)
                        op="="; op2=nil; version2=nil
                end
                return name, op, version, op2, version2
        else
                raise QueryError.new("Bad query #{query}")
        end
end