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.



499
500
501
# File 'lib/brauser/browser.rb', line 499

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.



485
486
487
488
489
490
491
492
493
# File 'lib/brauser/browser.rb', line 485

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