Skip to content
This repository has been archived by the owner on Sep 20, 2021. It is now read-only.

Matches operator does not match #97

Open
sanderdekroon opened this issue Oct 6, 2016 · 1 comment
Open

Matches operator does not match #97

sanderdekroon opened this issue Oct 6, 2016 · 1 comment

Comments

@sanderdekroon
Copy link

sanderdekroon commented Oct 6, 2016

I really love this project, it's working great so far! Except one thing, which I'm probably failing to understand (correctly).
I'm trying to match a 'description' with a partial string. I've found the matches operator and created the following rule:
description matches "somestring"

I load up the context, the rule, etc. And run it against this context:
lorem ipsum dolor sit somestring amet

Now I'm expecting this to return true (as 'somestring' matches a part of the context. Yet it returns false. I was expecting a similar functionality like the strpos function in PHP.

Am I using the operator wrong, or do I have to define a custom operator to accomplish something like this?

Thanks in advance.

To add a bit more context (hehe), this is the code that's supposed to run all the rules. If a rule matches a transaction. a category_id is added to the transaction.

$rules = Rule::all();
$transactions = Transaction::all();
foreach ($transactions as $transaction) {
    $context = new Context();
    $context['account_id'] = $transaction->account_id;
    $context['account_number'] = $transaction->account_number;
    $context['account_name'] = $transaction->account_name;
    $context['type'] = $transaction->type;
    $context['amount'] = $transaction->amount;
    $context['description'] = $transaction->description;
    $context['date'] = $transaction->date;
    $context['book_code'] = $transaction->book_code;

    $hoaRuler = new Ruler();

    foreach ($rules as $rule) {
        if ($hoaRuler->assert(strtolower($rule->rule), $context)) {
            $transaction->category_id = $rule->category_id;
            $transaction->save();
        }
    }
}
@Hywan
Copy link
Member

Hywan commented Oct 13, 2016

Huh? What? I sent a comment for this issue 6 days ago… damn…
So, from memory… the matches operator works as expected:

$ hoa ruler:assert -d 'foobarbaz' 'd matches "bar"'
$ echo $?
0 # success

$ hoa ruler:assert -d 'foobarbaz' 'd matches "qux"'
$ echo $?
1 # fail

Can we have more details please? Did you try with a minimal working example?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

2 participants