metafacture / metafacture-fix

Work in progress towards an implementation of the Fix language for Metafacture
Apache License 2.0
6 stars 2 forks source link

Implement boolean operators in conditionals. #165

Open blackwinter opened 2 years ago

blackwinter commented 2 years ago

Metafix should allow boolean operators (&&, ||) in conditionals, unlike Catmandu (apparently, Catmandu only supports control flow operators).

blackwinter commented 2 years ago

Would allow a much more concise notation and avoid repetition.

Old:

if any_match("@LeaderPos06", "[ij]")
  add_field("@facet_format", "Audio")
else
  if any_match("@006Pos00", "[ij]")
    add_field("@facet_format", "Audio")
  else
    if any_equal("@007Pos00", "s")
      add_field("@facet_format", "Audio")
    else
      if any_equal("337  .a", "audio")
        add_field("@facet_format", "Audio")
      else
        if any_equal("337  .b", "s")
          add_field("@facet_format", "Audio")
        else
          if any_equal("338  .a", "Audiodisk")
            add_field("@facet_format", "Audio")
          else
            paste("@type__008Pos26", "@type", "@008Pos26", join_char: "#")
            if any_equal("@type__008Pos26", "CF#h")
              add_field("@facet_format", "Audio")
            else
              paste("@006Pos00__006Pos09", "@006Pos00", "@006Pos09", join_char: "#")
              if any_equal("@006Pos00__006Pos09", "m#h")
                add_field("@facet_format", "Audio")
              end
            end
          end
        end
      end
    end
  end
end

New (see also #164):

if any_match("@LeaderPos06", "[ij]") ||
    any_match("@006Pos00", "[ij]") ||
    any_equal("@007Pos00", "s") ||
    any_equal("337  .b", "s") ||
    any_equal("338  .a", "Audiodisk") ||
    (any_equal("@type", "CF") && any_equal("@008Pos26", "h")) ||
    (any_equal("@006Pos00", "m") && any_equal("@006Pos09", "h"))
  add_field("@facet_format", "Audio")
end