Skip to content

Commit

Permalink
added console support, update readme, bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
SidOfc committed May 29, 2016
1 parent 6567172 commit e31a006
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 7 deletions.
4 changes: 4 additions & 0 deletions 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
Expand Down
68 changes: 63 additions & 5 deletions README.md
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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'

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -310,6 +348,7 @@ agent.to_a
# [:system_name, "windows"],
# [:system_version, "6.1"],
# [:system_architecture, "x64"],
# [:console_name, nil],
# [:locale, "as"]]
```

Expand All @@ -326,6 +365,7 @@ agent.to_h
# :system_name=>"windows",
# :system_version=>"6.1",
# :system_architecture=>"x64",
# :console_name => nil,
# :locale=>"as"}
```

Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -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`
Expand Down
16 changes: 16 additions & 0 deletions lib/browserino/core/questions.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/browserino/version.rb
@@ -1,3 +1,3 @@
module Browserino
VERSION = '2.8.2'.freeze
VERSION = '2.9.0'.freeze
end
2 changes: 1 addition & 1 deletion spec/user_agents_consoles.rb
Expand Up @@ -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,
}
}

Expand Down

0 comments on commit e31a006

Please sign in to comment.