Added some more operators.

Attribute + {n} is still not working.
This commit is contained in:
mark_story 2012-01-22 20:15:58 -05:00
parent 6c87be97ef
commit 9269a6dcde
2 changed files with 21 additions and 0 deletions

View file

@ -737,4 +737,16 @@ class Set2Test extends CakeTestCase {
$this->assertEquals(5, $result[3]['id']);
}
/**
* Test comparison operators.
*
* @return void
*/
public function testExtractAttributeComparison() {
$data = self::articleData();
$result = Set2::extract($data, '{n}.Comment.{n}.[user_id > 2]');
$this->assertEquals($data[0]['Comment'][1], $result);
}
}

View file

@ -158,6 +158,7 @@ class Set2 {
} else {
// attributes
foreach ($item as $k => $v) {
debug(array($k => $v));
if (self::_matches(array($k => $v), $token)) {
$next[] = $v;
}
@ -211,6 +212,14 @@ class Set2 {
return $prop == $val;
} elseif ($op === '!=') {
return $prop != $val;
} elseif ($op === '>') {
return $prop > $val;
} elseif ($op === '<') {
return $prop < $val;
} elseif ($op === '>=') {
return $prop >= $val;
} elseif ($op === '<=') {
return $prop <= $val;
}
}
return false;