MapCSS in progress. Vast amounts still to do, but the meat of it is here. POIs are...
[potlatch2.git] / net / systemeD / halcyon / styleparser / Condition.as
1 package net.systemeD.halcyon.styleparser {
2
3         // valid conditions:
4         // _type_       _params_
5         // regex        key, regex
6         // eq           key, value
7
8         public class Condition {
9                 public var type:String;         // eq, regex, lt, gt etc.
10                 public var params:Array;        // e.g. ('highway','primary')
11                 
12                 // ------------------------------------------------------------------------------------------
13                 // Constructor function
14                 
15                 public function Condition(t:String='', ...a) {
16                         type=t; params=a;
17                 }
18                 
19                 // ------------------------------------------------------------------------------------------
20                 // Test a hash against this condition
21
22                 public function test(tags:Object):Boolean {
23                         switch (type) {
24                                 case 'eq':              return (tags[params[0]]==params[1]); break;
25                                 case 'ne':              return (tags[params[0]]!=params[1]); break;
26                                 case 'regex':   var r:RegExp=new RegExp(params[1],"i");
27                                                                 return (r.test(tags[params[0]])); break;
28                                 case 'true':    return (tags[params[0]]=='true' || tags[params[0]]=='yes' || tags[params[0]]=='1'); break;
29                                 case 'untrue':  return (tags[params[0]]!='true' && tags[params[0]]!='yes' && tags[params[0]]!='1'); break;
30                                 case 'set':             return (tags[params[0]]!=undefined && tags[params[0]]!=''); break;
31                                 case 'unset':   return (tags[params[0]]==undefined || tags[params[0]]==''); break;
32                                 case '<':               return (Number(tags[params[0]])< Number(params[1])); break;
33                                 case '<=':              return (Number(tags[params[0]])<=Number(params[1])); break;
34                                 case '>':               return (Number(tags[params[0]])> Number(params[1])); break;
35                                 case '>=':              return (Number(tags[params[0]])>=Number(params[1])); break;
36                         }
37                         return false;
38                 }
39
40         public function toString():String {
41             return "Condition("+type+":"+params+")";
42         }
43
44
45         }
46
47 }