Module: Brauser::Definitions

Defined in:
lib/brauser/definitions/base.rb,
lib/brauser/definitions/browser.rb,
lib/brauser/definitions/language.rb,
lib/brauser/definitions/platform.rb

Overview

Definitions used by brauser.

Defined Under Namespace

Classes: Base, Browser, Language, Platform

Class Method Summary collapse

Class Method Details

.browsersHash

Returns the list of browser that can be recognized.

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

Returns:

  • (Hash)

    The list of browser that can be recognized.



34
35
36
# File 'lib/brauser/definitions/base.rb', line 34

def self.browsers
  @definitions[:browsers]
end

.languagesHash

Returns the list of languages that can be recognized.

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

Returns:

  • (Hash)

    The list of languages that can be recognized.



52
53
54
# File 'lib/brauser/definitions/base.rb', line 52

def self.languages
  @definitions[:languages]
end

.platformsHash

Returns the list of platforms that can be recognized.

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

Returns:

  • (Hash)

    The list of platform that can be recognized.



43
44
45
# File 'lib/brauser/definitions/base.rb', line 43

def self.platforms
  @definitions[:platforms]
end

.register(type, *args, **kwargs, &block) ⇒ Object

Registers a new definition.

Parameters:

  • type (Symbol)

    The type of the definition. Can be :browser, :language, :platform.

  • args (Array)

    The arguments of the definition.

  • kwargs (Hash)

    The keyword arguments of the definition.

  • block (Proc)

    The block of the definition.



15
16
17
18
19
20
21
22
23
24
25
26
27
# 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