From e31a006a267d3d9f921d6e3e9e3ffdda613994c2 Mon Sep 17 00:00:00 2001 From: Sidney Liebrand Date: Sun, 29 May 2016 20:00:23 +0200 Subject: [PATCH] added console support, update readme, bump version --- CHANGELOG.md | 4 ++ README.md | 68 +++++++++++++++++++++++++++++--- lib/browserino/core/questions.rb | 16 ++++++++ lib/browserino/version.rb | 2 +- spec/user_agents_consoles.rb | 2 +- 5 files changed, 85 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e4fdeb8..b636092 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ ## CHANGELOG _dates are in dd-mm-yyyy format_ +#### 02-03-2016 VERSION 2.7.0 + +- Added `solaris?` method + #### 22-01-2016 VERSION 2.6.0 - Fixed `to_a` method diff --git a/README.md b/README.md index ca73f1f..d3134e9 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,25 @@ Useragent references: _dates are in dd-mm-yyyy format_ _older changes can be found in the [CHANGELOG.md](/CHANGELOG.md)_ +#### 29-05-2016 VERSION 2.9.0 + +- Stricter checking for: + * `social_media?` + * `bot?` + * `browser?` + * `platform?` + + These functions used to be callable with unrelated symbols + (e.g `agent.platform?(:firefox) # => true`). This is now also filtered. +- Added support for consoles + * Added `console?` method + * Added `wii?`, `playstation?`, `xbox?` and `nintendo_ds?` methods +- Added general `name` method to store any browser / bot / search engine / social media agent +- `social_media_name`, `search_engine_name` and `bot_name` are now aliasses of `name` +- removed `:bot_name` from data structure (now stored in a general `name` property) +- removed `:browser_name` from data structure (now stored in a general `name` property) +- Added `console_name` method to get the name of a console + #### 27-05-2016 VERSION 2.8.2 - Removed Guard gem dependency @@ -34,10 +53,6 @@ _older changes can be found in the [CHANGELOG.md](/CHANGELOG.md)_ - Fixed `respond_to?` method signature - Added executable for parsing useragents in terminal -#### 02-03-2016 VERSION 2.7.0 - -- Added `solaris?` method - ## Installation Add the following to your applications Gemfile: @@ -130,6 +145,11 @@ agent = Browserino.parse 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleW agent.name # => 'brave' +# or using browser_name + +agent.browser_name +# => 'brave' + agent.browser_version # => '0.7.7' @@ -162,6 +182,13 @@ The samples below are all valid calls with their respective outputs, using the ` agent = Browserino.parse 'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; AS; rv:11.0) like Gecko' ``` +#### Note + +The methods `social_media_name`, `search_engine_name`, `bot_name` and `browser_name` +are *all* aliasses of the general `name` method. + +The exceptions to this rule are `system_name` and `console_name`. They each have their own method. + ##### Quick usage ```ruby @@ -198,6 +225,9 @@ agent.system_version agent.system_architecture # => 'x64' +agent.console_name +# => nil + # two formats possible: 'aa' or `aa-bb` agent.locale # => 'as' @@ -243,6 +273,14 @@ agent.platform? :windows agent.platform? :windows, version: '7' # => true +# returns true if console is known +agent.console? +# => false + +# returns true if specific console +agent.console? :xbox +# => false + # returns true if user agent is empty or a bot is recognized agent.bot? # => false @@ -310,6 +348,7 @@ agent.to_a # [:system_name, "windows"], # [:system_version, "6.1"], # [:system_architecture, "x64"], +# [:console_name, nil], # [:locale, "as"]] ``` @@ -326,6 +365,7 @@ agent.to_h # :system_name=>"windows", # :system_version=>"6.1", # :system_architecture=>"x64", +# :console_name => nil, # :locale=>"as"} ``` @@ -380,7 +420,7 @@ agent.platform? :android, version: :jelly_bean_16 # => true ``` -##### `platform?`, `browser?`, `bot?` `search_engine?` and `social_media?` methods +##### `platform?`, `browser?`, `bot?`, `console?`, `search_engine?` and `social_media?` methods As you've seen above, the `platform?` function can take two arguments, a symbol with the system name and optionally a hash with a `:version` key to supply a version, the `browser?` method works in exactly the same way. @@ -432,6 +472,24 @@ agent.search_engine? :google agent.search_engine? :ddg ``` +**consoles** + +* `xbox` +* `nintendo_ds` +* `wii` +* `playstation` + +Examples: + +```ruby +agent.playstation? +agent.wii? + +agent.console? + +agent.console? :facebook +``` + **social media** * `facebook` or `fb` diff --git a/lib/browserino/core/questions.rb b/lib/browserino/core/questions.rb index 70e250b..4f3542a 100644 --- a/lib/browserino/core/questions.rb +++ b/lib/browserino/core/questions.rb @@ -59,6 +59,22 @@ def ddg?(*arg) duckduckgo?(*arg) end + def playstation? + invertable console_name == 'playstation' + end + + def nintendo_ds? + invertable console_name == 'nintendo_ds' + end + + def xbox? + invertable console_name == 'xbox' + end + + def wii? + invertable console_name == 'wii' + end + def bot?(name = nil) is_bot = ua.strip.empty? || !bot_name.nil? is_name = name.nil? || name.to_s.downcase.tr('_', ' ') == bot_name diff --git a/lib/browserino/version.rb b/lib/browserino/version.rb index f3411b0..5bcc768 100644 --- a/lib/browserino/version.rb +++ b/lib/browserino/version.rb @@ -1,3 +1,3 @@ module Browserino - VERSION = '2.8.2'.freeze + VERSION = '2.9.0'.freeze end diff --git a/spec/user_agents_consoles.rb b/spec/user_agents_consoles.rb index 40da83b..00cd7f5 100644 --- a/spec/user_agents_consoles.rb +++ b/spec/user_agents_consoles.rb @@ -3,7 +3,7 @@ module Consoles XBOX = { 'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0; Xbox)' => { console_name: 'xbox', - console?: true + console?: true, } }