Class: Brauser::Definitions::Platform
- Defined in:
- lib/brauser/definitions/platform.rb
Overview
A definition of a platform.
Instance Attribute Summary collapse
-
#matcher ⇒ Regexp|Proc
readonly
The pattern or the block to recognize the platform.
-
#name ⇒ String
readonly
The platform name.
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(id, name, matcher = /.*/, **_, &block) ⇒ Platform
constructor
Creates a new definition.
-
#match(header, engine) ⇒ Boolean|NilClass
Matches against an header.
Constructor Details
#initialize(id, name, matcher = /.*/, **_, &block) ⇒ Platform
Creates a new definition.
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
#matcher ⇒ Regexp|Proc (readonly)
Returns 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. **Ignore 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 |
#name ⇒ String (readonly)
Returns 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. **Ignore 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
#match(header, engine) ⇒ Boolean|NilClass
Matches against an header.
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 |