Module: Brauser::BrowserMethods::Parsing

Included in:
Brauser::Browser
Defined in:
lib/brauser/browser.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.



444
445
446
# File 'lib/brauser/browser.rb', line 444

def parse_accept_language(accept_language = nil)
  accept_language.ensure_string.gsub(/;q=[\d.]+/, "").split(",").collect {|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.



430
431
432
433
434
435
436
437
438
# File 'lib/brauser/browser.rb', line 430

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