Module: Webdriver::UserAgent::Devices

Included in:
Driver
Defined in:
lib/webdriver-user-agent/devices.rb

Instance Method Summary collapse

Instance Method Details

#agent_string_for(device) ⇒ Object



19
20
21
22
23
24
# File 'lib/webdriver-user-agent/devices.rb', line 19

def agent_string_for(device)
  device = (device ? keyify(device) : :iphone)
  user_agent_string = (device == :random ? random_user_agent : devices[device][:user_agent])
  raise "Unsupported user agent: '#{device}'." unless user_agent_string
  user_agent_string
end

#devicesObject



7
8
9
10
# File 'lib/webdriver-user-agent/devices.rb', line 7

def devices
  string_hash = YAML.safe_load_file devices_file, aliases: true
  JSON.parse(JSON[string_hash], symbolize_names: true)
end

#resolution_for(device_name, orientation, user_width, user_height) ⇒ Object



12
13
14
15
16
17
# File 'lib/webdriver-user-agent/devices.rb', line 12

def resolution_for(device_name, orientation, user_width, user_height)
  return [user_width.to_i, user_height.to_i] if ((user_width.to_i + user_height.to_i) > 1)

  device = devices[keyify(device_name)][keyify(orientation)]
  [device[:width],device[:height]]
end