class MobilappUseragent

Constants

MATCHER
VERSION

Attributes

client[R]
device[R]
os[R]

Public Class Methods

new(client_name, client_version = nil, comments = nil) click to toggle source
# File lib/mobilapp_useragent.rb, line 35
def initialize(client_name, client_version = nil, comments = nil)

        if client_name
                @client = Agent::Client.new client_name.downcase, client_version
        else
                raise ArgumentError, "expected a value for @client"
        end

        parse_comments comments

end
parse(string) click to toggle source
# File lib/mobilapp_useragent.rb, line 16
def self.parse(string)

        if string.nil? || string == ""
                raise ArgumentError, "Expected a value for 'string'"
        end

        agents = []

        while m = string.to_s.match(MATCHER)

                agents << new(m[1], m[2], m[4])
                string = string[m[0].length..-1].strip

        end

        agents.first

end

Private Instance Methods

parse_comments(comments) click to toggle source
# File lib/mobilapp_useragent.rb, line 49
def parse_comments comments

        os = comments.to_s.match(/#{Agent::Os::OS.join('|')}/i)

        # Set OS from comments
        if os.nil?

                @os = Agent::Os.new 'ios', nil

        else

                os_version = comments.to_s.match(/(#{os})\s+?((?:(\d+)\.)?(?:(\d+)\.)?(\*|\d+))/i)
                @os = Agent::Os.new os[0].downcase, os_version[2]


                @device = Agent::Device.new( @os.name, comments )

        end



end