Class: Brauser::Definitions::Platform

Inherits:
Base
  • Object
show all
Defined in:
lib/brauser/definitions/platform.rb

Overview

A definition of a platform.

Instance Attribute Summary (collapse)

Attributes inherited from Base

#id

Instance Method Summary (collapse)

Constructor Details

- (Platform) initialize(id, name, matcher = /.*/, **_, &block)

Creates a new definition.

Parameters:

  • id (Symbol)

    The platform id.

  • name (String)

    The platform name.

  • matcher (Regexp|Proc) (defaults to: /.*/)

    The pattern or the block to recognize the platform. Ignored if a block is given.



22
23
24
25
26
# File 'lib/brauser/definitions/platform.rb', line 22

def initialize(id, name, matcher = /.*/, **_, &block)
  @id = id
  @name = name
  @matcher = block ? block : matcher
end

Instance Attribute Details

- (Regexp|Proc) matcher (readonly)

Returns The pattern or the block to recognize the platform.

Returns:

  • (Regexp|Proc)

    The pattern or the block to recognize the platform.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/brauser/definitions/platform.rb', line 14

class Platform < Base
  attr_reader :name, :matcher

  # Creates a new definition.
  #
  # @param id [Symbol] The platform id.
  # @param name [String] The platform name.
  # @param matcher [Regexp|Proc] The pattern or the block to recognize the platform. **Ignored if a block is given.**
  def initialize(id, name, matcher = /.*/, **_, &block)
    @id = id
    @name = name
    @matcher = block ? block : matcher
  end

  # Matches against an header.
  #
  # @param header [String] The header to match.
  # @param engine [Symbol] The engine to match.
  # @return [Boolean|NilClass] True if match succeeded, `false` or `nil` otherwise.
  def match(header, engine)
    if @matcher.is_a?(Regexp)
      @matcher.match(header)
    else
      @matcher.call(header, engine)
    end
  end
end

- (String) name (readonly)

Returns The platform name.

Returns:

  • (String)

    The platform name.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/brauser/definitions/platform.rb', line 14

class Platform < Base
  attr_reader :name, :matcher

  # Creates a new definition.
  #
  # @param id [Symbol] The platform id.
  # @param name [String] The platform name.
  # @param matcher [Regexp|Proc] The pattern or the block to recognize the platform. **Ignored if a block is given.**
  def initialize(id, name, matcher = /.*/, **_, &block)
    @id = id
    @name = name
    @matcher = block ? block : matcher
  end

  # Matches against an header.
  #
  # @param header [String] The header to match.
  # @param engine [Symbol] The engine to match.
  # @return [Boolean|NilClass] True if match succeeded, `false` or `nil` otherwise.
  def match(header, engine)
    if @matcher.is_a?(Regexp)
      @matcher.match(header)
    else
      @matcher.call(header, engine)
    end
  end
end

Instance Method Details

- (Boolean|NilClass) match(header, engine)

Matches against an header.

Parameters:

  • header (String)

    The header to match.

  • engine (Symbol)

    The engine to match.

Returns:

  • (Boolean|NilClass)

    True if match succeeded, false or nil otherwise.



33
34
35
36
37
38
39
# File 'lib/brauser/definitions/platform.rb', line 33

def match(header, engine)
  if @matcher.is_a?(Regexp)
    @matcher.match(header)
  else
    @matcher.call(header, engine)
  end
end