From fbb9576748a77ccac0ac5c97c5e400bef22841c7 Mon Sep 17 00:00:00 2001 From: TobiasNx <61879957+TobiasNx@users.noreply.github.com> Date: Tue, 9 Apr 2024 21:33:45 +0200 Subject: [PATCH] Update Fix-functions-and-Cookbook.md Bring the documentation to status of Fix Release 1.0.0 https://github.com/metafacture/metafacture-fix/releases/tag/1.0.0 --- docs/fix/Fix-functions-and-Cookbook.md | 74 +++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/docs/fix/Fix-functions-and-Cookbook.md b/docs/fix/Fix-functions-and-Cookbook.md index 02745ae..58acb51 100644 --- a/docs/fix/Fix-functions-and-Cookbook.md +++ b/docs/fix/Fix-functions-and-Cookbook.md @@ -5,7 +5,7 @@ parent: Fix nav_order: 2 --- -This page is a replication of the passage of the Fix Readme.md. +This page is a replication of the passage [Fix Functions and Cookbook](https://github.com/metafacture/metafacture-fix?tab=readme-ov-file#functions-and-cookbook) of the Fix Readme.md. Status: [Fix Release 1.0.0](https://github.com/metafacture/metafacture-fix/releases/tag/1.0.0) ## Functions and cookbook @@ -73,6 +73,8 @@ Does nothing. It is used for benchmarking in Catmandu. nothing() ``` +[Example in Playground](https://metafacture.org/playground/?example=nothing) + ##### `put_filemap` Defines an external map for [lookup](#lookup) from a file or a URL. Maps with more than 2 columns are supported but are reduced to a defined key and a value column. @@ -81,6 +83,8 @@ Defines an external map for [lookup](#lookup) from a file or a URL. Maps with mo put_filemap("", "", sep_char: "\t") ``` +[Example in Playground](https://metafacture.org/playground/?example=put_filemap) + The separator (`sep_char`) will vary depending on the source file, e.g.: | Type | Separator | @@ -110,6 +114,8 @@ put_map("", ) ``` +[Example in Playground](https://metafacture.org/playground/?example=put_map) + ##### `put_rdfmap` Defines an external RDF map for lookup from a file or an HTTP(S) resource. @@ -121,6 +127,8 @@ put_rdfmap("", "", target: "") put_rdfmap("", "", target: "", select_language: "") ``` +[Example in Playground](https://metafacture.org/playground/?example=put_rdfmap) + ##### `put_var` Defines a single global variable that can be referenced with `$[]`. @@ -129,6 +137,8 @@ Defines a single global variable that can be referenced with `$[]` put_var("", "") ``` +[Example in Playground](https://metafacture.org/playground/?example=put_var) + ##### `put_vars` Defines multiple global variables that can be referenced with `$[]`. @@ -140,6 +150,8 @@ put_vars( ) ``` +[Example in Playground](https://metafacture.org/playground/?example=put_vars) + #### Record-level functions ##### `add_field` @@ -150,6 +162,8 @@ Creates a field with a defined value. add_field("", "") ``` +[Example in Playground](https://metafacture.org/playground/?example=add_field) + ##### `array` Converts a hash/object into an array. @@ -184,6 +198,8 @@ end call_macro(""[, ...]) ``` +[Example in Playground](https://metafacture.org/playground/?example=call_macro) + ##### `copy_field` Copies a field from an existing field. @@ -192,6 +208,9 @@ Copies a field from an existing field. copy_field("", "") ``` +[Example in Playground](https://metafacture.org/playground/?example=copy_field) + + ##### `format` Replaces the value with a formatted (`sprintf`-like) version. @@ -224,6 +243,9 @@ Moves a field from an existing field. Can be used to rename a field. move_field("", "") ``` +[Example in Playground](https://metafacture.org/playground/?example=move_field) + + ##### `parse_text` Parses a text into an array or hash of values. @@ -255,6 +277,8 @@ paste("my.string", "~Hi", "a", "~how are you?") # "my.string": "Hi eeny how are you?" ``` +[Example in Playground](https://metafacture.org/playground/?example=paste) + ##### `print_record` Prints the current record as JSON either to standard output or to a file. @@ -304,6 +328,8 @@ Removes a field. remove_field("") ``` +[Example in Playground](https://metafacture.org/playground/?example=remove_field) + ##### `rename` Replaces a regular expression pattern in subfield names of a field. Does not change the name of the source field itself. @@ -312,6 +338,8 @@ Replaces a regular expression pattern in subfield names of a field. Does not cha rename("", "", "") ``` +[Example in Playground](https://metafacture.org/playground/?example=rename) + ##### `retain` Deletes all fields except the ones listed (incl. subfields). @@ -320,6 +348,8 @@ Deletes all fields except the ones listed (incl. subfields). retain(""[, ...]) ``` +[Example in Playground](https://metafacture.org/playground/?example=retain) + ##### `set_array` Creates a new array (with optional values). @@ -329,6 +359,8 @@ set_array("") set_array("", ""[, ...]) ``` +[Example in Playground](https://metafacture.org/playground/?example=set_array) + ##### `set_field` Creates (or replaces) a field with a defined value. @@ -368,6 +400,8 @@ Deletes empty fields, arrays and objects. vacuum() ``` +[Example in Playground](https://metafacture.org/playground/?example=vacuum) + #### Field-level functions ##### `append` @@ -378,6 +412,8 @@ Adds a string at the end of a field value. append("", "") ``` +[Example in Playground](https://metafacture.org/playground/?example=append) + ##### `capitalize` Upcases the first character in a field value. @@ -386,6 +422,8 @@ Upcases the first character in a field value. capitalize("") ``` +[Example in Playground](https://metafacture.org/playground/?example=capitalize) + ##### `count` Counts the number of elements in an array or a hash and replaces the field value with this number. @@ -402,6 +440,8 @@ Downcases all characters in a field value. downcase("") ``` +[Example in Playground](https://metafacture.org/playground/?example=downcase) + ##### `filter` Only keeps field values that match the regular expression pattern. Works only with array of strings/repeated fields. @@ -418,6 +458,8 @@ Flattens a nested array field. flatten("") ``` +[Example in Playground](https://metafacture.org/playground/?example=flatten) + ##### `from_json` Replaces the string with its JSON deserialization. @@ -452,6 +494,8 @@ Options: isbn(""[, to: ""][, verify_check_digit: ""][, error_string: ""]) ``` +[Example in Playground](https://metafacture.org/playground/?example=isbn) + ##### `join_field` Joins an array of strings into a single string. @@ -460,6 +504,8 @@ Joins an array of strings into a single string. join_field("", "") ``` +[Example in Playground](https://metafacture.org/playground/?example=join_field) + ##### `lookup` Looks up matching values in a map and replaces the field value with this match. [External files](#put_filemap), [internal maps](#put_map) as well as [RDF resources](#put_rdfmap) can be used. @@ -527,6 +573,8 @@ Adds a string at the beginning of a field value. prepend("", "") ``` +[Example in Playground](https://metafacture.org/playground/?example=prepend) + ##### `replace_all` Replaces a regular expression pattern in field values with a replacement string. Regexp capturing is possible; refer to capturing groups by number (`$`) or name (`${}`). @@ -535,6 +583,8 @@ Replaces a regular expression pattern in field values with a replacement string. replace_all("", "", "") ``` +[Example in Playground](https://metafacture.org/playground/?example=replace_all) + ##### `reverse` Reverses the character order of a string or the element order of an array. @@ -553,6 +603,8 @@ sort_field("", reverse: "true") sort_field("", numeric: "true") ``` +[Example in Playground](https://metafacture.org/playground/?example=sort_field) + ##### `split_field` Splits a string into an array and replaces the field value with this array. @@ -561,6 +613,8 @@ Splits a string into an array and replaces the field value with this array. split_field("", "") ``` +[Example in Playground](https://metafacture.org/playground/?example=split_field) + ##### `substring` Replaces a string with its substring as defined by the start position (offset) and length. @@ -598,6 +652,8 @@ Deletes whitespace at the beginning and the end of a field value. trim("") ``` +[Example in Playground](https://metafacture.org/playground/?example=trim) + ##### `uniq` Deletes duplicate values in an array. @@ -606,6 +662,9 @@ Deletes duplicate values in an array. uniq("") ``` +[Example in Playground](https://metafacture.org/playground/?example=uniq) + + ##### `upcase` Upcases all characters in a field value. @@ -614,6 +673,8 @@ Upcases all characters in a field value. upcase("") ``` +[Example in Playground](https://metafacture.org/playground/?example=upcase) + ##### `uri_encode` Encodes a field value as URI. Aka percent-encoding. @@ -645,6 +706,8 @@ if end ``` +[Example in Playground](https://metafacture.org/playground/?example=reject) + ### Binds #### `do list` @@ -657,6 +720,8 @@ do list(path: "") end ``` +[Example in Playground](https://metafacture.org/playground/?example=do_list) + Only the current element is accessible in this case (as the root element). When specifying a variable name for the current element, the record remains accessible as the root element and the current element is accessible through the variable name: @@ -667,6 +732,8 @@ do list(path: "", "var": "") end ``` +[Example in Playground](https://metafacture.org/playground/?example=do_list_with_var) + #### `do list_as` Iterates over each _named_ element of an array (like [`do list`](#do-list) with a variable name). If multiple arrays are given, iterates over the _corresponding_ elements from each array (i.e., all elements with the same array index, skipping elements whose arrays have already been exhausted). @@ -700,6 +767,8 @@ do once() end ``` +[Example in Playground](https://metafacture.org/playground/?example=do_once) + In order to execute multiple blocks only once, tag them with unique identifiers: ```perl @@ -736,6 +805,8 @@ end call_macro(""[, ...]) ``` +[Example in Playground](https://metafacture.org/playground/?example=do_put_macro) + ### Conditionals Conditionals start with `if` in case of affirming the condition or `unless` rejecting the condition. @@ -871,4 +942,3 @@ Executes the functions if/unless the field value does not match the regular expr ##### `str_match` Executes the functions if/unless the string matches the regular expression pattern. -