select
Karchnu 2020-12-01 23:45:12 +01:00
parent ed703d7496
commit 2a5d5066dd
1 changed files with 35 additions and 2 deletions

View File

@ -42,8 +42,7 @@ class SelectApplication
# 1.1 get rules and stuff. # 1.1 get rules and stuff.
intent = ARGV[0] intent = ARGV[0]
case intent proc = case intent
# String comparison. # String comparison.
when /(?<attribute>[^ ]+)[ ]*(?<comparison>(eq|neq|=~)+)[ ]*(?<value>[^ ]+)/ when /(?<attribute>[^ ]+)[ ]*(?<comparison>(eq|neq|=~)+)[ ]*(?<value>[^ ]+)/
attribute = $~["attribute"] attribute = $~["attribute"]
@ -51,17 +50,51 @@ class SelectApplication
value = $~["value"] value = $~["value"]
pp! "string comparison", attribute, comparison, 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. # Numerical comparison.
when /(?<attribute>[^ ]+)[ ]*(?<comparison>[=<>]+)[ ]*(?<value>[^ ]+)/ when /(?<attribute>[^ ]+)[ ]*(?<comparison>[=<>]+)[ ]*(?<value>[^ ]+)/
attribute = $~["attribute"] attribute = $~["attribute"]
comparison = $~["comparison"] comparison = $~["comparison"]
value = $~["value"] value = $~["value"]
pp! "numerical comparison", attribute, comparison, 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 /</
puts "attribute #{attribute} should be less than #{value}"
else
raise "numerical comparison '#{comparison}' not understood"
end
}
else else
STDERR.puts "cannot understand the intent of #{intent}" STDERR.puts "cannot understand the intent of #{intent}"
exit 1 exit 1
end end
proc.call CBOR::Any.new "this is my attribute"
# TODO: FIXME # TODO: FIXME
exit 0 exit 0