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 /