Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/json_logic/operation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,16 @@ class Operation
end
end,
'if' => ->(v, d) {
v.each_slice(2) do |condition, value|
return condition if value.nil?
return value if condition.truthy?
v.each_slice(2) do |condition_and_value|
# If this slice a single value? It's an else value only.
if condition_and_value.size == 1
return condition_and_value.first
else
condition, value = condition_and_value
return value if condition.truthy?
end
end
nil
},
'==' => ->(v, d) { v[0].to_s == v[1].to_s },
'===' => ->(v, d) { v[0] == v[1] },
Expand Down
2 changes: 1 addition & 1 deletion test/json_logic_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class JSONLogicTest < Minitest::Test
test_suite_url = 'http://jsonlogic.com/tests.json'
tests = JSON.parse(open(test_suite_url).read)
tests = JSON.parse(URI.open(test_suite_url).read)
count = 1
tests.each do |pattern|
next unless pattern.is_a?(Array)
Expand Down