Module: Brauser::BrowserMethods::General::ClassMethods

Defined in:
lib/brauser/browser.rb

Overview

Class methods.

Instance Method Summary collapse

Instance Method Details

#browsersHash

Returns the list of browser that can be recognized.

The keys are the browser name, the values are arrays of the name matcher, the version match and the label.

Returns:

  • (Hash)

    The list of browser that can be recognized.



280
281
282
# File 'lib/brauser/browser.rb', line 280

def browsers
  @definitions[:browsers]
end

#compare_versions(v1 = "", operator = :eq, v2 = "") ⇒ Boolean

Compares two versions.

Parameters:

  • v1 (String) (defaults to: "")

    The first versions to compare.

  • operator (Symbol) (defaults to: :eq)

    The operator to use for comparison, can be one of [:lt, :lte, :eq, :gte, :gt].

  • v2 (Symbol) (defaults to: "")

    The second version to compare.

Returns:

  • (Boolean)

    true if comparison is valid, false otherwise.



308
309
310
311
312
313
314
315
316
317
318
# File 'lib/brauser/browser.rb', line 308

def compare_versions(v1 = "", operator = :eq, v2 = "")
  valid_results = {lt: [-1], lte: [-1, 0], eq: [0], gte: [0, 1], gt: [1]}.fetch(operator, [])

  if valid_results.present? && v1.ensure_string.present? then
    p1, p2 = find_relevant_tokens(v1, v2)
    p1, p2 = normalize_tokens(p1, p2)
    valid_results.include?(p1 <=> p2)
  else
    false
  end
end

#languagesHash

Returns the list of languages that can be recognized.

The keys are the languages code, the values the labels.

Returns:

  • (Hash)

    The list of languages that can be recognized.



298
299
300
# File 'lib/brauser/browser.rb', line 298

def languages
  @definitions[:languages]
end

#platformsHash

Returns the list of platforms that can be recognized.

The keys are the platform name, values are arrays of the matcher and the label.

Returns:

  • (Hash)

    The list of platform that can be recognized.



289
290
291
# File 'lib/brauser/browser.rb', line 289

def platforms
  @definitions[:platforms]
end