Class: Brauser::Query
- Inherits:
-
Object
- Object
- Brauser::Query
- Defined in:
- lib/brauser/query.rb
Overview
Instance Attribute Summary collapse
-
#result ⇒ Boolean
The current result.
-
#target ⇒ Browser
The current browser.
Instance Method Summary collapse
-
#accepts(langs = []) ⇒ Query
Check if the browser accepts the specified languages.
-
#accepts?(langs = []) ⇒ Boolean
Check if the browser accepts the specified languages.
-
#initialize(target, result = true) ⇒ Query
constructor
Creates a new query.
-
#is(names = [], versions = {}, platforms = []) ⇒ Query
Checks if the browser is a specific name and optionally of a specific version and platform.
-
#is?(names = [], versions = {}, platforms = []) ⇒ Boolean
Checks if the browser is a specific name and optionally of a specific version and platform.
-
#on(platforms = []) ⇒ Query
Check if the browser is on a specific platform.
-
#on?(platforms = []) ⇒ Boolean
Check if the browser is on a specific platform.
-
#v(versions = {}) ⇒ Query
Checks if the browser is a specific version.
-
#v?(versions = {}) ⇒ Boolean
Checks if the browser is a specific version.
Constructor Details
#initialize(target, result = true) ⇒ Query
Creates a new query.
29 30 31 32 |
# File 'lib/brauser/query.rb', line 29 def initialize(target, result = true) @target = target @result = result end |
Instance Attribute Details
#result ⇒ Boolean
Returns 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 |
#target ⇒ Browser
Returns 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.
105 106 107 108 |
# File 'lib/brauser/query.rb', line 105 def accepts(langs = []) @result = self.accepts?(langs) self end |
#accepts?(langs = []) ⇒ Boolean
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.
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
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.
86 87 88 89 |
# File 'lib/brauser/query.rb', line 86 def on(platforms = []) @result = self.on?(platforms) self end |
#on?(platforms = []) ⇒ Boolean
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.
67 68 69 70 |
# File 'lib/brauser/query.rb', line 67 def v(versions = {}) @result = self.v?(versions) self end |