From 2a5d5066dd50e2e1febbcc5571eaaf21b6d0c669 Mon Sep 17 00:00:00 2001 From: Karchnu Date: Tue, 1 Dec 2020 23:45:12 +0100 Subject: [PATCH] Proc. --- src/oselect/main.cr | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/src/oselect/main.cr b/src/oselect/main.cr index e296136..dc1d87a 100644 --- a/src/oselect/main.cr +++ b/src/oselect/main.cr @@ -42,8 +42,7 @@ class SelectApplication # 1.1 get rules and stuff. intent = ARGV[0] - case intent - + proc = case intent # String comparison. when /(?[^ ]+)[ ]*(?(eq|neq|=~)+)[ ]*(?[^ ]+)/ attribute = $~["attribute"] @@ -51,17 +50,51 @@ class SelectApplication value = $~["value"] pp! "string comparison", attribute, comparison, value + ->(v : JSON::Any | CBOR::Any) { + case comparison + when /neq/ + puts "attribute #{attribute} shouldn't be equal to #{value}" + when /eq/ + puts "attribute #{attribute} should be equal to #{value}" + when /=~/ + puts "attribute #{attribute} should match #{value}" + else + raise "string comparison '#{comparison}' not understood" + end + } + # Numerical comparison. when /(?[^ ]+)[ ]*(?[=<>]+)[ ]*(?[^ ]+)/ attribute = $~["attribute"] comparison = $~["comparison"] value = $~["value"] pp! "numerical comparison", attribute, comparison, value + + ->(v : JSON::Any | CBOR::Any) { + case comparison + when /!=/ + puts "attribute #{attribute} shouldn't be equal to #{value}" + when /==/ + puts "attribute #{attribute} should be equal to #{value}" + when />=/ + puts "attribute #{attribute} should be greater or equal than #{value}" + when /<=/ + puts "attribute #{attribute} should be less or equal than #{value}" + when />/ + puts "attribute #{attribute} should be greater than #{value}" + when /