Proc.
parent
ed703d7496
commit
2a5d5066dd
|
@ -42,8 +42,7 @@ class SelectApplication
|
|||
# 1.1 get rules and stuff.
|
||||
intent = ARGV[0]
|
||||
|
||||
case intent
|
||||
|
||||
proc = case intent
|
||||
# String comparison.
|
||||
when /(?<attribute>[^ ]+)[ ]*(?<comparison>(eq|neq|=~)+)[ ]*(?<value>[^ ]+)/
|
||||
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>[^ ]+)[ ]*(?<comparison>[=<>]+)[ ]*(?<value>[^ ]+)/
|
||||
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 /</
|
||||
puts "attribute #{attribute} should be less than #{value}"
|
||||
else
|
||||
raise "numerical comparison '#{comparison}' not understood"
|
||||
end
|
||||
}
|
||||
else
|
||||
STDERR.puts "cannot understand the intent of #{intent}"
|
||||
exit 1
|
||||
end
|
||||
|
||||
proc.call CBOR::Any.new "this is my attribute"
|
||||
|
||||
# TODO: FIXME
|
||||
exit 0
|
||||
|
||||
|
|
Loading…
Reference in New Issue