class UserAgent
def self.parse(string)
def self.parse(string) agents = [] while m = string.match(MATCHER) agents << new(m[1], m[2], m[4]) string = string.sub(m[0], '').strip end Browsers.extend(agents) agents end
def <=>(other)
Any comparsion between two user agents with different products will
def <=>(other) if @product == other.product if @version && other.version @version <=> other.version else 0 end else false end end
def eql?(other)
def eql?(other) @product == other.product && @version == other.version && @comment == other.comment end
def initialize(product, version = nil, comment = nil)
def initialize(product, version = nil, comment = nil) if product @product = product else raise ArgumentError, "expected a value for product" end if version && !version.empty? @version = version else @version = nil end if comment.respond_to?(:split) @comment = comment.split("; ") else @comment = comment end end
def to_s
def to_s to_str end
def to_str
def to_str if @product && @version && @comment "#{@product}/#{@version} (#{@comment.join("; ")})" elsif @product && @version "#{@product}/#{@version}" elsif @product && @comment "#{@product} (#{@comment.join("; ")})" else @product end end