Module: Brauser::Browseable::Parsing

Included in:
Brauser::Browser
Defined in:
lib/brauser/browseable/parsing.rb

Overview

Methods to parse the user agent.

Instance Method Summary (collapse)

Instance Method Details

- (Array) parse_accept_language(accept_language = nil)

Parses the Accept-Language header.

Parameters:

  • accept_language (String) (defaults to: nil)

    The Accept-Language header.

Returns:

  • (Array)

    The list of accepted languages.



29
30
31
# File 'lib/brauser/browseable/parsing.rb', line 29

def parse_accept_language(accept_language = nil)
  accept_language.ensure_string.gsub(/;q=[\d.]+/, "").split(",").map { |l| l.downcase.strip }.select { |l| l.present? }
end

- (Boolean) parse_agent(agent = nil)

Parses the User-Agent header.

Parameters:

  • agent (String) (defaults to: nil)

    The User-Agent header.

Returns:

  • (Boolean)

    true if the browser was detected, false otherwise.



15
16
17
18
19
20
21
22
23
# File 'lib/brauser/browseable/parsing.rb', line 15

def parse_agent(agent = nil)
  agent = agent.ensure_string

  @name, _ = match_name_and_version(agent)
  @version = adjust_version(@version)
  @platform = match_platform(agent)

  (@name != :unknown) ? true : false
end