class Brauser::Definitions::Browser

A definition of a platform.

@attribute [r] name

@return [String] The platform name.

@attribute [r] engine_matcher

@return [Regexp|Proc] The pattern or the block to recognize the engine.

@attribute [r] version_matcher

@return [Regexp|Proc] The pattern or the block to recognize the version.

Attributes

engine_matcher[R]
name[R]
version_matcher[R]

Public Class Methods

new(id, name, engine_matcher, version_matcher, **_) click to toggle source

Creates a new definition.

@param id [Symbol] The platform id. @param name [String] The platform name. @param engine_matcher [Regexp|Proc] The pattern or the block to recognize the engine. @param version_matcher [Regexp|Proc] The pattern or the block to recognize the version.

# File lib/brauser/definitions/browser.rb, line 25
def initialize(id, name, engine_matcher, version_matcher, **_)
  @id = id
  @name = name
  @engine_matcher = engine_matcher
  @version_matcher = version_matcher
end

Public Instance Methods

match(header) click to toggle source

Matches against an header.

@param header [String] The header to match @return [Array|NilClass] An array with the engine and the version if match succeeded, `false` or `nil` otherwise.

# File lib/brauser/definitions/browser.rb, line 36
def match(header)
  # First of all, match the engine
  engine = perform_match(@engine_matcher, header) ? @id : nil

  if engine
    version = extract_version(perform_match(@version_matcher, header))
    platform = extract_platform(header, engine)
    [Brauser::Value.new(engine), Brauser::Value.new(version), Brauser::Value.new(platform)]
  end
end