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 multiple `elsif` statements in `if` conditional. #164

Closed blackwinter closed 2 years ago

blackwinter commented 2 years ago

Metafix should allow multiple elsif statements in if conditional, just like Catmandu.

blackwinter commented 2 years ago

Would allow a more concise notation (and avoid "nesting hell").

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 #165):

if any_match("@LeaderPos06", "[ij]")
  add_field("@facet_format", "Audio")
elsif any_match("@006Pos00", "[ij]")
  add_field("@facet_format", "Audio")
elsif any_equal("@007Pos00", "s")
  add_field("@facet_format", "Audio")
elsif any_equal("337  .a", "audio")
  add_field("@facet_format", "Audio")
elsif any_equal("337  .b", "s")
  add_field("@facet_format", "Audio")
elsif 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
blackwinter commented 2 years ago

Functional review: @TobiasNx Code review: @fsteeg