Chris Craik | f516a62 | 2015-04-01 17:52:39 -0700 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <!-- |
| 3 | Copyright 2015 The Chromium Authors. All rights reserved. |
| 4 | Use of this source code is governed by a BSD-style license that can be |
| 5 | found in the LICENSE file. |
| 6 | --> |
| 7 | |
| 8 | <link rel="import" href="/core/scripting_object.html"> |
| 9 | |
Chris Craik | 44c2820 | 2015-05-12 17:25:16 -0700 | [diff] [blame^] | 10 | <script> |
| 11 | 'use strict'; |
Chris Craik | f516a62 | 2015-04-01 17:52:39 -0700 | [diff] [blame] | 12 | |
Chris Craik | 44c2820 | 2015-05-12 17:25:16 -0700 | [diff] [blame^] | 13 | tv.exportTo('tv.e.tquery', function() { |
| 14 | function Filter() { |
| 15 | tv.c.ScriptingObject.call(this); |
| 16 | } |
| 17 | |
| 18 | Filter.normalizeFilterExpression = function(filterExpression) { |
| 19 | // Shortcut: naked strings and regexps can be used to match against slice |
| 20 | // titles. |
| 21 | if (filterExpression instanceof String || |
| 22 | typeof(filterExpression) == 'string' || |
| 23 | filterExpression instanceof RegExp) { |
| 24 | var filter = new tv.e.tquery.FilterHasTitle(filterExpression); |
| 25 | return filter; |
| 26 | } |
| 27 | return filterExpression; |
| 28 | }; |
| 29 | |
| 30 | Filter.prototype = { |
| 31 | __proto__: tv.c.ScriptingObject.prototype, |
Chris Craik | f516a62 | 2015-04-01 17:52:39 -0700 | [diff] [blame] | 32 | |
| 33 | evaluate: function(context) { |
| 34 | throw new Error('Not implemented'); |
| 35 | }, |
| 36 | |
| 37 | matchValue_: function(value, expected) { |
| 38 | if (expected instanceof RegExp) |
| 39 | return expected.test(value); |
| 40 | else if (expected instanceof Function) |
| 41 | return expected(value); |
| 42 | return value === expected; |
Chris Craik | f516a62 | 2015-04-01 17:52:39 -0700 | [diff] [blame] | 43 | } |
Chris Craik | 44c2820 | 2015-05-12 17:25:16 -0700 | [diff] [blame^] | 44 | }; |
| 45 | |
| 46 | return { |
| 47 | Filter: Filter |
| 48 | }; |
| 49 | }); |
| 50 | </script> |