class Aua

Constants

MAJOR_VERSION
MATCHER
VERSION

Attributes

os_name[R]
os_version[R]
parts[R]
platform[R]
raw[R]
version[R]

Public Class Methods

new(string="") click to toggle source
# File lib/aua.rb, line 8
def initialize(string="")
  @raw = string.to_s
  parse
end
parse(raw) click to toggle source
# File lib/aua.rb, line 13
def self.parse(raw)
  new(raw)
end

Public Instance Methods

app() click to toggle source
# File lib/aua.rb, line 66
def app
  products[0]
end
app_comments() click to toggle source
# File lib/aua.rb, line 74
def app_comments
  @app_comments ||= (comments.first || []) + [""]*5
end
app_comments_string() click to toggle source
# File lib/aua.rb, line 78
def app_comments_string
  @app_comments_string ||= (comments.first || []).join(";")
end
comments() click to toggle source
# File lib/aua.rb, line 70
def comments
  @comments ||= parts.map{|p| p[2] }
end
comments_string() click to toggle source
# File lib/aua.rb, line 82
def comments_string
  @comments_string ||= comments.flatten.join(";")
end
major_version() click to toggle source
# File lib/aua.rb, line 50
def major_version
  @major_version ||= (version || "") =~ MAJOR_VERSION ? "#{$1}.#{$2}" : version
end
name() click to toggle source
# File lib/aua.rb, line 31
def name
  @name unless unknown?
  if simple?
    app
  else
    raw
  end
end
os_major_version() click to toggle source
# File lib/aua.rb, line 54
def os_major_version
  @os_major_version ||= (os_version || "") =~ MAJOR_VERSION ? "#{$1}.#{$2}" : os_version
end
os_string() click to toggle source
# File lib/aua.rb, line 95
def os_string
  @os_string ||= comments.first && comments.first[2]
end
parse() click to toggle source
# File lib/aua.rb, line 17
def parse
  string = @raw.dup
  @parts = []
  while m = string.match(MATCHER)
    @parts << [m[1] ? m[1].sub(/;$/,"") : m[1], m[2], m[4] ? m[4].split(/\s?;\s?/) : []]
    string = string.sub(m[0], '').strip
  end

  Aua::Agents.extend_agent(self)
  Aua::OperatingSystems.extend_agent(self)
end
platform_string() click to toggle source
# File lib/aua.rb, line 91
def platform_string
  @platform_string ||= comments.first && comments.first.first
end
products() click to toggle source
# File lib/aua.rb, line 58
def products
  @products ||= parts.map{|p| p[0] }
end
simple?() click to toggle source
# File lib/aua.rb, line 103
def simple?
  products.size == 1 && versions.size <= 1 && comments == [[]]
end
to_s() click to toggle source
# File lib/aua.rb, line 107
def to_s
  return "Unknown: #{raw}#{" (simple)" if simple?}" if unknown?
  "#{type} #{name}/#{version} #{os_name}/#{os_version} #{platform}"
end
type() click to toggle source
# File lib/aua.rb, line 40
def type
  @type || :Unknown
end
unknown?() click to toggle source
# File lib/aua.rb, line 99
def unknown?
  type == :Unknown
end
version_of(product) click to toggle source
# File lib/aua.rb, line 86
def version_of(product)
  i = products.index(product.to_s)
  versions[i] if i && versions[i] != ""
end
versions() click to toggle source
# File lib/aua.rb, line 62
def versions
  @versions ||= parts.map{|p| p[1] != "" ? p[1] : nil }
end