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

Matches operator does not match #97

Description

@sanderdekroon

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();
        }
    }
}

Activity

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions