module Brauser::Definitions

Definitions used by brauser.

Public Class Methods

browsers() click to toggle source

Returns the list of browser that can be recognized.

The keys are the ids, the values are the definitions.

@return [Hash] The list of browser that can be recognized.

# File lib/brauser/definitions/base.rb, line 34
def self.browsers
  @definitions[:browsers]
end
languages() click to toggle source

Returns the list of languages that can be recognized.

The keys are the ids, the values are the definitions.

@return [Hash] The list of languages that can be recognized.

# File lib/brauser/definitions/base.rb, line 52
def self.languages
  @definitions[:languages]
end
platforms() click to toggle source

Returns the list of platforms that can be recognized.

The keys are the ids, the values are the definitions.

@return [Hash] The list of platform that can be recognized.

# File lib/brauser/definitions/base.rb, line 43
def self.platforms
  @definitions[:platforms]
end
register(type, *args, **kwargs, &block) click to toggle source

Registers a new definition.

@param type [Symbol] The type of the definition. Can be `:browser`, `:language`, `:platform`. @param args [Array] The arguments of the definition. @param kwargs [Hash] The keyword arguments of the definition. @param block [Proc] The block of the definition.

# File lib/brauser/definitions/base.rb, line 15
def self.register(type, *args, **kwargs, &block)
  klass =
    case type
    when :browser then Brauser::Definitions::Browser
    when :language then Brauser::Definitions::Language
    when :platform then Brauser::Definitions::Platform
    else raise(ArgumentError, "Invalid definition type \"#{type}\".")
    end

  @definitions ||= {browsers: {}, languages: {}, platforms: {}}
  definition = klass.new(*args, **kwargs, &block)
  @definitions["#{type}s".to_sym][definition.id] = definition
end