package ua_os_info;
use strict;

#-------------------------------------------------------------------------------
sub new {
	my $class = shift;
	my $self = bless ({}, $class);

	return $self;
}
#-------------------------------------------------------------------------------
sub get_os {
	my $self = shift;
	my $ua = lc(shift || '');
	my $os_list = $self->get_vars();

	my $os_name = '';

	#-----------------------------------------------------------------------
	foreach my $os (@{$os_list}) {
		my $i = index($ua, lc($os->{search}));
		unless ($i < 0) {
			$os_name = $os->{name};
			last;
		}
	}

	#-----------------------------------------------------------------------
	unless ($os_name) {
		if (index($ua, 'linux') >=0) {
			$os_name = 'Linux';
		} elsif (index($ua, 'win') >=0) {
			$os_name = $ua =~ m/(win[^;]+)/;
		} else {
			$os_name = 'Other OS';
		}
	}

	return $os_name;
}
#-------------------------------------------------------------------------------
sub get_vars {
	my $self = shift;
	my $os_list = [
		{
			name	=> 'Android',
			search	=> 'Android',
		},
		{
			name	=> 'Macintosh',
			search	=> 'Macintosh',
		},
		{
			name	=> 'Ubuntu',
			search	=> 'Ubuntu',
		},
		{
			name	=> 'Debian',
			search	=> 'Debian',
		},
		{
			name	=> 'Sun Solaris',
			search	=> 'SunOS',
		},
		{
			name	=> 'Symbian OS',
			search	=> 'Symbian',
		},
		{
			name	=> 'FreeBSD',
			search	=> 'FreeBSD',
		},
		{
			name	=> 'Fedora Core',
			search	=> 'Fedora',
		},
		{
			name	=> 'Ubuntu',
			search	=> 'Ubuntu',
		},
		{
			name	=> 'SUSE',
			search	=> 'SUSE',
		},
		{
			name	=> 'Gentoo',
			search	=> 'Gentoo',
		},
		{
			name	=> 'Mandriva',
			search	=> 'Mandriva',
		},
		{
			name	=> 'OS/2',
			search	=> 'OS/2',
		},
		{
			name	=> 'PalmOS',
			search	=> 'PalmOS',
		},
		{
			name	=> 'Windows 3.11',
			search	=> 'Win3.11',
		},
		{
			name	=> 'Windows 3.1',
			search	=> 'Win3.1',
		},
		{
			name	=> 'Windows 95',
			search	=> 'Windows 95',
		},
		{
			name	=> 'Windows 95',
			search	=> 'Win95',
		},
		{
			name	=> 'Windows 98',
			search	=> 'Windows 98',
		},
		{
			name	=> 'Windows 98',
			search	=> 'Win98',
		},
		{
			name	=> 'Windows ME',
			search	=> 'Windows ME',
		},
		{
			name	=> 'Windows 2000',
			search	=> 'Windows 2000',
		},
		{
			name	=> 'Windows 2000',
			search	=> 'Windows NT 5.0',
		},
		{
			name	=> 'Windows 2000',
			search	=> 'WinNT5.0',
		},
		{
			name	=> 'Windows 2000',
			search	=> 'Win2000',
		},
		{
			name	=> 'Windows XP',
			search	=> 'Windows XP',
		},
		{
			name	=> 'Windows XP',
			search	=> 'Windows NT 5.1',
		},
		{
			name	=> 'Windows XP',
			search	=> 'WinNT5.1',
		},
		{
			name	=> 'Windows Server 2003',
			search	=> 'Windows NT 5.2',
		},
		{
			name	=> 'Windows Server 2003',
			search	=> 'WinNT5.2',
		},
		{
			name	=> 'Windows Vista',
			search	=> 'Windows NT 6.0',
		},
		{
			name	=> 'Windows Vista',
			search	=> 'WinNT6.0',
		},
		{
			name	=> 'Windows 7',
			search	=> 'Windows NT 6.1',
		},
		{
			name	=> 'Windows 7',
			search	=> 'Windows NT 7.0',
		},
		{
			name	=> 'Windows CE',
			search	=> 'Windows CE',
		},
	];

	return $os_list;
}
#-------------------------------------------------------------------------------
1;
