Module: Brauser::BrowserMethods::PartialQuerying

Included in:
Brauser::Browser
Defined in:
lib/brauser/browser.rb

Overview

Methods to query with chaining.

Instance Method Summary collapse

Instance Method Details

#accepts(langs = []) ⇒ Query

Check if the browser accepts the specified languages.

Parameters:

  • langs (String|Array) (defaults to: [])

    A list of languages to match against.

Returns:

  • (Query)

    A query which can evaluated for concatenation or result.



548
549
550
551
552
# File 'lib/brauser/browser.rb', line 548

def accepts(langs = [])
  parse_accept_language(@accept_language) if !@languages

  ::Brauser::Query.new(self, (@languages & langs.ensure_array(nil, true, true, :to_s)).present?)
end

#is(names = [], versions = {}, platforms = []) ⇒ Query

Checks if the browser is a specific name and optionally of a specific version and platform.

Parameters:

  • names (Symbol|Array) (defaults to: [])

    A list of specific names to match. Also, this meta-names are supported: :capable and :tablet.

  • versions (String|Hash) (defaults to: {})

    A string in the form operator version && ... (example: >= 7 && < 4) or an hash with specific version to match against, in form {:operator => version}, where operator is one of :lt, :lte, :eq, :gt, :gte.

  • platforms (Symbol|Array) (defaults to: [])

    A list of specific platform to match. Valid values are all those possible for the platform attribute.

Returns:

  • (Query)

    A query which can evaluated for concatenation or result.

See Also:

  • #v?
  • #on?


509
510
511
512
513
514
515
516
517
518
519
520
521
# File 'lib/brauser/browser.rb', line 509

def is(names = [], versions = {}, platforms = [])
  parse_agent(@agent) if !@name

  names = adjust_names(names)
  versions = parse_versions_query(versions)
  platforms = platforms.ensure_array

  ::Brauser::Query.new(self,
    (names.blank? || (names.include?(@name) && check_capable(names))) &&
    (versions.blank? || v?(versions)) &&
    (platforms.blank? || on?(platforms))
  )
end

#on(platforms = []) ⇒ Query

Check if the browser is on a specific platform.

Parameters:

  • platforms (Symbol|Array) (defaults to: [])

    A list of specific platform to match.

Returns:

  • (Query)

    A query which can evaluated for concatenation or result.



538
539
540
541
542
# File 'lib/brauser/browser.rb', line 538

def on(platforms = [])
  parse_agent(@agent) if !@platform

  ::Brauser::Query.new(self, platforms.blank? || platforms.ensure_array(nil, true, true, :to_sym).include?(@platform))
end

#v(versions = {}) ⇒ Query

Checks if the browser is a specific version.

Parameters:

  • versions (String|Hash) (defaults to: {})

    A string in the form operator version && ... (example: >= 7 && < 4) or an hash with specific version to match against, in form {:operator => version}, where operator is one of :lt, :lte, :eq, :gt, :gte.

Returns:

  • (Query)

    A query which can evaluated for concatenation or result.



527
528
529
530
531
532
# File 'lib/brauser/browser.rb', line 527

def v(versions = {})
  parse_agent(@agent) if !@version
  versions = versions.is_a?(String) ? parse_versions_query(versions) : versions.ensure_hash

  ::Brauser::Query.new(self, versions.all? { |operator, value| Brauser::Browser.compare_versions(@version, operator, value) })
end