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.



29
30
31
32
# File 'lib/brauser/query.rb', line 29

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

Instance Attribute Details

#resultBoolean

Returns The current result.

Returns:

  • (Boolean)

    The current result.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/brauser/query.rb', line 21

class Query
  attr_accessor :target
  attr_accessor :result

  # Creates a new query.
  #
  # @param target [Browser] The current browser.
  # @param result [Boolean] The current result.
  def initialize(target, result = true)
    @target = target
    @result = result
  end

  # Checks if the browser is a specific name and optionally of a specific version and platform.
  #
  # @see #version?
  # @see #on?
  #
  # @param names [Symbol|Array] A list of specific names to match. Also, this meta-names are supported: `:capable` and `:tablet`.
  # @param versions [Hash] An hash with specific version to match against. Need to be in any form that {#v} understands.
  # @param platforms [Symbol|Array] A list of specific platform to match. Valid values are all those possible for the platform attribute.
  # @return [Query] The query itself.
  def is(names = [], versions = {}, platforms = [])
    @result = self.is?(names, versions, platforms)
    self
  end

  # 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}.
  #
  # @see #version?
  # @see #on?
  #
  # @param names [Symbol|Array] A list of specific names to match. Also, this meta-names are supported: `:capable` and `:tablet`.
  # @param versions [Hash] An hash with specific version to match against. Need to be in any form that {#v} understands.
  # @param platforms [Symbol|Array] A list of specific platform to match. Valid values are all those possible for the platform attribute.
  # @return [Boolean] `true` if current browser matches, `false` otherwise.
  def is?(names = [], versions = {}, platforms = [])
    @result ? @target.is?(names, versions, platforms) : @result
  end

  # Checks if the browser is a specific version.
  #
  # @param versions [String|Hash] 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`.
  # @return [Query] The query itself.
  def v(versions = {})
    @result = self.v?(versions)
    self
  end

  # Checks if the browser is a specific version.
  #
  # This version returns a boolean and it is equal to append a call to {#result} to the method {#v}.
  #
  # @param versions [String|Hash] 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`.
  # @return [Boolean] `true` if current browser matches, `false` otherwise.
  def v?(versions = {})
    @result ? @target.v?(versions) : @result
  end

  # Check if the browser is on a specific platform.
  #
  # @param platforms [Symbol|Array] A list of specific platform to match.
  # @return [Query] The query itself.
  def on(platforms = [])
    @result = self.on?(platforms)
    self
  end

  # 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}.
  #
  # @param platforms [Symbol|Array] A list of specific platform to match.
  # @return [Boolean] `true` if current browser matches, `false` otherwise.
  def on?(platforms = [])
    @result ? @target.on?(platforms) : @result
  end

  # Check if the browser accepts the specified languages.
  #
  # @param langs [String|Array] A list of languages to match against.
  # @return [Query] The query itself.
  def accepts(langs = [])
    @result = self.accepts?(langs)
    self
  end

  # 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}.
  #
  # @param langs [String|Array] A list of languages to match against.
  # @return [Boolean] `true` if current browser matches, `false` otherwise.
  def accepts?(langs = [])
    @result ? @target.accepts?(langs) : @result
  end
end

#targetBrowser

Returns The current browser.

Returns:

  • (Browser)

    The current browser.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/brauser/query.rb', line 21

class Query
  attr_accessor :target
  attr_accessor :result

  # Creates a new query.
  #
  # @param target [Browser] The current browser.
  # @param result [Boolean] The current result.
  def initialize(target, result = true)
    @target = target
    @result = result
  end

  # Checks if the browser is a specific name and optionally of a specific version and platform.
  #
  # @see #version?
  # @see #on?
  #
  # @param names [Symbol|Array] A list of specific names to match. Also, this meta-names are supported: `:capable` and `:tablet`.
  # @param versions [Hash] An hash with specific version to match against. Need to be in any form that {#v} understands.
  # @param platforms [Symbol|Array] A list of specific platform to match. Valid values are all those possible for the platform attribute.
  # @return [Query] The query itself.
  def is(names = [], versions = {}, platforms = [])
    @result = self.is?(names, versions, platforms)
    self
  end

  # 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}.
  #
  # @see #version?
  # @see #on?
  #
  # @param names [Symbol|Array] A list of specific names to match. Also, this meta-names are supported: `:capable` and `:tablet`.
  # @param versions [Hash] An hash with specific version to match against. Need to be in any form that {#v} understands.
  # @param platforms [Symbol|Array] A list of specific platform to match. Valid values are all those possible for the platform attribute.
  # @return [Boolean] `true` if current browser matches, `false` otherwise.
  def is?(names = [], versions = {}, platforms = [])
    @result ? @target.is?(names, versions, platforms) : @result
  end

  # Checks if the browser is a specific version.
  #
  # @param versions [String|Hash] 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`.
  # @return [Query] The query itself.
  def v(versions = {})
    @result = self.v?(versions)
    self
  end

  # Checks if the browser is a specific version.
  #
  # This version returns a boolean and it is equal to append a call to {#result} to the method {#v}.
  #
  # @param versions [String|Hash] 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`.
  # @return [Boolean] `true` if current browser matches, `false` otherwise.
  def v?(versions = {})
    @result ? @target.v?(versions) : @result
  end

  # Check if the browser is on a specific platform.
  #
  # @param platforms [Symbol|Array] A list of specific platform to match.
  # @return [Query] The query itself.
  def on(platforms = [])
    @result = self.on?(platforms)
    self
  end

  # 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}.
  #
  # @param platforms [Symbol|Array] A list of specific platform to match.
  # @return [Boolean] `true` if current browser matches, `false` otherwise.
  def on?(platforms = [])
    @result ? @target.on?(platforms) : @result
  end

  # Check if the browser accepts the specified languages.
  #
  # @param langs [String|Array] A list of languages to match against.
  # @return [Query] The query itself.
  def accepts(langs = [])
    @result = self.accepts?(langs)
    self
  end

  # 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}.
  #
  # @param langs [String|Array] A list of languages to match against.
  # @return [Boolean] `true` if current browser matches, `false` otherwise.
  def accepts?(langs = [])
    @result ? @target.accepts?(langs) : @result
  end
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.



105
106
107
108
# File 'lib/brauser/query.rb', line 105

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.



116
117
118
# File 'lib/brauser/query.rb', line 116

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:



43
44
45
46
# File 'lib/brauser/query.rb', line 43

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:



59
60
61
# File 'lib/brauser/query.rb', line 59

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.



86
87
88
89
# File 'lib/brauser/query.rb', line 86

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.



97
98
99
# File 'lib/brauser/query.rb', line 97

def on?(platforms = [])
  @result ? @target.on?(platforms) : @result
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)

    The query itself.



67
68
69
70
# File 'lib/brauser/query.rb', line 67

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

#v?(versions = {}) ⇒ Boolean

Checks if the browser 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.



78
79
80
# File 'lib/brauser/query.rb', line 78

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