Class: Brauser::Query
- Inherits:
-
Object
- Object
- Brauser::Query
- Defined in:
- lib/brauser/query.rb
Overview
A query to a browser. This class enables concatenation, like:
ruby
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)
-
- (Boolean) result
The current result.
-
- (Browser) target
The current browser.
Instance Method Summary (collapse)
-
- (Query) accepts(langs = [])
Check if the browser accepts the specified languages.
-
- (Boolean) accepts?(langs = [])
Check if the browser accepts the specified languages.
-
- (Query) initialize(target, result = true)
constructor
Creates a new query.
-
- (Query) is(names = [], versions = {}, platforms = [])
Checks if the browser is a specific name and optionally of a specific version and platform.
-
- (Boolean) is?(names = [], versions = {}, platforms = [])
Checks if the browser is a specific name and optionally of a specific version and platform.
-
- (Query) on(platforms = [])
Check if the browser is on a specific platform.
-
- (Boolean) on?(platforms = [])
Check if the browser is on a specific platform.
-
- (Query) v(versions = {})
Checks if the browser is a specific version.
-
- (Boolean) v?(versions = {})
Checks if the browser is a specific version.
Constructor Details
- (Query) initialize(target, result = true)
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
- (Boolean) result
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 |
- (Browser) target
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
- (Query) accepts(langs = [])
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 |
- (Boolean) accepts?(langs = [])
116 117 118 |
# File 'lib/brauser/query.rb', line 116 def accepts?(langs = []) @result ? @target.accepts?(langs) : @result end |
- (Query) is(names = [], versions = {}, platforms = [])
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 |
- (Boolean) is?(names = [], versions = {}, platforms = [])
59 60 61 |
# File 'lib/brauser/query.rb', line 59 def is?(names = [], versions = {}, platforms = []) @result ? @target.is?(names, versions, platforms) : @result end |
- (Query) on(platforms = [])
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 |
- (Boolean) on?(platforms = [])
97 98 99 |
# File 'lib/brauser/query.rb', line 97 def on?(platforms = []) @result ? @target.on?(platforms) : @result end |
- (Query) v(versions = {})
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 |