Class: DeviceWizard::WindowsResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/device_wizard.rb

Constant Summary collapse

KEYWORD =
'windows nt'
REGEX =
Regexp.new('windows nt ([0-9]{1,}[\.0-9]{0,})')
NTVERSION =
[ '4.0', '5.0', '5.01', '5.1', '5.2', '6.0', '6.1', '6.2', '6.3' ]
NTNAME =
[ 'NT 4.0', '2000', '2000 SP1', 'XP', 'XP x64', 'Vista', '7', '8', '8.1' ]

Instance Method Summary collapse

Instance Method Details

#get_version(user_agent) ⇒ Object



407
408
409
410
411
412
413
414
415
416
417
418
# File 'lib/device_wizard.rb', line 407

def get_version(user_agent)
  user_agent.downcase!
  result = UNKNOWN

  if REGEX =~ user_agent
    if NTVERSION.index($1)
      result = NTNAME[NTVERSION.index($1)]
    else
      result = $1
    end
  end
end

#identify(user_agent) ⇒ Object



420
421
422
423
424
425
426
427
428
429
430
431
# File 'lib/device_wizard.rb', line 420

def identify(user_agent)
  user_agent.downcase!

  if !user_agent.include? KEYWORD
    return nil
  end

  result = OperatingSystemDetails.new
  result.name = 'Windows'
  result.version = get_version(user_agent)
  return result
end