Skip to content

Transformers for applying simple transformations of variables

Currently there is no possibility (except for using custom Converters) to even apply very simple transformations to variables, e.g. (use cases):

  • parse "Mon" from a filename using a regexp, but set a property to "Monday"
  • increase an integer derived from a filename by one
  • set a variable to "April" if the value of an element in a file was "4".
  • ...

I would like to propose a straight-forward method to apply common simple transformations to variables without making the cfoods turing-complete or allowing custom code within the cfoods.

DateDir:
  type: Directory
  match: ^Day_(?P<day_short>.*)$  # Example: Day_Mon
  transform:
    MakeDayLong:
      in: $day_short
      out: $day_long
      functions:
      - ifelse:  # name of the function
          match: Mon  # match is one specific argument
          then: Monday  # then another one
      - ifelse:  # next function
          match: Tue
          then: Tuesday

      - ...
  records:
    DayFolder:
      Day: $day_long
    ...

This example is just meant to sketch the idea, of course the detailed syntax is up to discussion. Important requirements:

  • There can be (again) builtin functions and custom functions, that need to be declared in the metadata of the cfood and can use custom python packages.
  • The whole thing should be compatible to our macro system, to allow creating reusable parts.

Some questions:

  • It looks a bit verbose in the above example. We should check what's really needed? Is the name "MakeDayLong" really needed?
  • Is "in" and "out" really necessary?

This is really just a first sketch, but I think a feature like that is urgently needed. So I hope for a lively discussion about the idea. :-)