Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get device name from android devices. #232

Merged
merged 2 commits into from
Nov 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Detect Edge based on Chrome correctly.
- Improve Yandex detection.
- Add Sputnik (https://browser.sputnik.ru)
- Detect Android devices.
- Add ScoutURLMonitor to the bot list.

## 2.6.1
Expand Down
2 changes: 2 additions & 0 deletions lib/browser/device.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require "browser/device/base"
require "browser/device/android"
require "browser/device/unknown"
require "browser/device/ipad"
require "browser/device/ipod_touch"
Expand Down Expand Up @@ -45,6 +46,7 @@ def self.matchers
Ipad,
Iphone,
IpodTouch,
Android,
Unknown
]
end
Expand Down
20 changes: 20 additions & 0 deletions lib/browser/device/android.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

module Browser
class Device
class Android < Base
def id
:unknown
end

def name
ua[/\(Linux.*?; Android.*?; ([-_a-z0-9 ]+) Build[^)]+\)/i, 1] ||
"Unknown"
end

def match?
ua =~ /Android/
end
end
end
end
2 changes: 1 addition & 1 deletion lib/browser/device/tv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def name
end

def match?
ua =~ /(tv|Android.*?ADT-1|Nexus Player)/i
ua =~ /(\btv|Android.*?ADT-1|Nexus Player)/i
end
end
end
Expand Down
20 changes: 20 additions & 0 deletions test/unit/device_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,24 @@ def id
refute device.mobile?
end
end

{
"ANDROID_CUPCAKE" => "T-Mobile G1",
"ANDROID_DONUT" => "SonyEricssonX10i",
"ANDROID_ECLAIR_21" => "Nexus One",
"ANDROID_FROYO" => "HTC_DesireHD_A9191",
"ANDROID_GINGERBREAD" => "Sensation_4G",
"ANDROID_HONEYCOMB_30" => "Xoom",
"ANDROID_ICECREAM" => "sdk",
"ANDROID_JELLYBEAN_41" => "Nexus S",
"ANDROID_JELLYBEAN_42" => "Nexus 10",
"ANDROID_JELLYBEAN_43" => "Nexus 7",
"CUSTOM_APP" => "HTC Ruby",
"NOOK" => "NOOK BNTV250A"
}.each do |key, name|
test "detect device name of #{key} as #{name}" do
device = Browser::Device.new(Browser[key])
assert_equal name, device.name
end
end
end