Class: Brauser::Query

Inherits:
Object
  • Object
show all
Defined in:
lib/brauser/query.rb

Overview

A query to a browser. This class enables concatenation, like:

Brauser::Browser.new.is(:msie).v(">= 7").on?(:windows)

To end concatenation, use the ? form of the queries or call .result.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, result = true) ⇒ Query

Creates a new query.

Parameters:

  • target (Browser)

    The current browser.

  • result (Boolean) (defaults to: true)

    The current result.



27
28
29
30
# File 'lib/brauser/query.rb', line 27

def initialize(target, result = true)
  @target = target
  @result = result
end

Instance Attribute Details

#resultObject

The current result.



21
22
23
# File 'lib/brauser/query.rb', line 21

def result
  @result
end

#targetObject

The current browser.



18
19
20
# File 'lib/brauser/query.rb', line 18

def target
  @target
end

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)

    The query itself.



103
104
105
106
# File 'lib/brauser/query.rb', line 103

def accepts(langs = [])
  @result = self.accepts?(langs)
  self
end

#accepts?(langs = []) ⇒ Boolean

Check if the browser accepts the specified languages.

This version returns a boolean and it is equal to append a call to #result to the method #accepts.

Parameters:

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

    A list of languages to match against.

Returns:

  • (Boolean)

    true if current browser matches, false otherwise.



114
115
116
# File 'lib/brauser/query.rb', line 114

def accepts?(langs = [])
  @result ? @target.accepts?(langs) : @result
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 (Hash) (defaults to: {})

    An hash with specific version to match against. Need to be in any form that #v understands.

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

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

Returns:

  • (Query)

    The query itself.

See Also:



41
42
43
44
# File 'lib/brauser/query.rb', line 41

def is(names = [], versions = {}, platforms = [])
  @result = self.is?(names, versions, platforms)
  self
end

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

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

This version returns a boolean and it is equal to append a call to #result to the method #is.

Parameters:

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

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

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

    An hash with specific version to match against. Need to be in any form that #v understands.

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

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

Returns:

  • (Boolean)

    true if current browser matches, false otherwise.

See Also:



57
58
59
# File 'lib/brauser/query.rb', line 57

def is?(names = [], versions = {}, platforms = [])
  @result ? @target.is?(names, versions, platforms) : @result
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)

    The query itself.



84
85
86
87
# File 'lib/brauser/query.rb', line 84

def on(platforms = [])
  @result = self.on?(platforms)
  self
end

#on?(platforms = []) ⇒ Boolean

Check if the browser is on a specific platform.

This version returns a boolean and it is equal to append a call to #result to the method #on.

Parameters:

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

    A list of specific platform to match.

Returns:

  • (Boolean)

    true if current browser matches, false otherwise.



95
96
97
# File 'lib/brauser/query.rb', line 95

def on?(platforms = [])
  @result ? @target.on?(platforms) : @result
end

#v(versions = {}) ⇒ Query

Checks if the brower 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)

    The query itself.



65
66
67
68
# File 'lib/brauser/query.rb', line 65

def v(versions = {})
  @result = self.v?(versions)
  self
end

#v?(versions = {}) ⇒ Boolean

Checks if the brower is a specific version.

This version returns a boolean and it is equal to append a call to #result to the method #v.

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:

  • (Boolean)

    true if current browser matches, false otherwise.



76
77
78
# File 'lib/brauser/query.rb', line 76

def v?(versions = {})
  @result ? @target.v?(versions) : @result
end