Skip to content

Commit

Permalink
Get device name from android devices.
Browse files Browse the repository at this point in the history
Close #231.
  • Loading branch information
fnando committed Nov 16, 2019
1 parent 05c2a72 commit c68e491
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
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

0 comments on commit c68e491

Please sign in to comment.