Module: Brauser::Browseable::Attributes

Included in:
Brauser::Browser
Defined in:
lib/brauser/browseable/attributes.rb

Overview

Methods to handle attributes.

Instance Method Summary (collapse)

Instance Method Details

- (String|Array) classes(join = " ", name = "", version = "version-", platform = "platform-", &block) Also known as: meta, to_s

Returns an array of information about the browser. Information are strings which are suitable to use as CSS classes.

For version, it will be included a class for every token of the version. For example, version 7.0.1.2 will return this:

ruby ["version-7", "version-7_0", "version-7_0_1", "version-7_0_1_2"]

If you provide a block (with accepts name, version and platform as arguments), it will be used for translating the name.

Parameters:

  • join (String|NilClass) (defaults to: " ")

    If non falsy, the separator to use to join information. If falsy, informations will be returned as array.

  • name (Boolean) (defaults to: "")

    If non falsy, the string to prepend to the name. If falsy, the name information will not be included.

  • version (String|NilClass) (defaults to: "version-")

    If non falsy, the string to prepend to the version. If falsy, the version information will not be included.

  • platform (String|NilClass) (defaults to: "platform-")

    If non falsy, the string to prepend to the platform. If falsy, the platform information will not be included.

  • block (Proc)

    A block to translate browser name.

Returns:

  • (String|Array)

    CSS ready information of the current browser.



46
47
48
49
50
# File 'lib/brauser/browseable/attributes.rb', line 46

def classes(join = " ", name = "", version = "version-", platform = "platform-", &block)
  platform = "platform-" if platform.is_a?(TrueClass)
  rv = [stringify_name(name, &block), stringify_version(version), !platform ? nil : (platform + @platform.to_s)].compact.flatten
  join ? rv.join(join) : rv
end

- (String) platform_name

Gets a human-readable platform name.

Returns:

  • (String)

    A readable platform name.



25
26
27
28
# File 'lib/brauser/browseable/attributes.rb', line 25

def platform_name
  parse_agent(@agent) unless @platform
  ::Brauser::Browser.platforms[@platform].try(:label) || "Unknown Platform"
end

- (String) readable_name

Gets a human-readable browser name.

Returns:

  • (String)

    A human-readable browser name.



15
16
17
18
19
20
# File 'lib/brauser/browseable/attributes.rb', line 15

def readable_name
  parse_agent(@agent) unless @name
  ::Brauser::Browser.browsers.fetch(@name).label
rescue KeyError
  "Unknown Browser"
end