diff --git a/README.md b/README.md index 354590e0..754c450a 100644 --- a/README.md +++ b/README.md @@ -170,6 +170,8 @@ Does nothing. It is used for benchmarking in Catmandu. nothing() ``` +[Playground-Example](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. @@ -178,6 +180,8 @@ Defines an external map for [lookup](#lookup) from a file or a URL. Maps with mo put_filemap("", "", sep_char: "\t") ``` +[Playground-Example](https://metafacture.org/playground/?example=put_filemap) + The separator (`sep_char`) will vary depending on the source file, e.g.: | Type | Separator | @@ -207,6 +211,8 @@ put_map("", ) ``` +[Playground-Example](https://metafacture.org/playground/?example=put_map) + ##### `put_rdfmap` Defines an external RDF map for lookup from a file or an HTTP(S) resource. @@ -218,6 +224,8 @@ put_rdfmap("", "", target: "") put_rdfmap("", "", target: "", select_language: "") ``` +[Playground-Example](https://metafacture.org/playground/?example=put_rdfmap) + ##### `put_var` Defines a single global variable that can be referenced with `$[]`. @@ -226,6 +234,8 @@ Defines a single global variable that can be referenced with `$[]` put_var("", "") ``` +[Playground-Example](https://metafacture.org/playground/?example=put_var) + ##### `put_vars` Defines multiple global variables that can be referenced with `$[]`. @@ -237,6 +247,8 @@ put_vars( ) ``` +[Playground-Example](https://metafacture.org/playground/?example=put_vars) + #### Record-level functions ##### `add_field` @@ -247,6 +259,8 @@ Creates a field with a defined value. add_field("", "") ``` +[Playground-Example](https://metafacture.org/playground/?example=add+field) + ##### `array` Converts a hash/object into an array. @@ -281,6 +295,8 @@ end call_macro(""[, ...]) ``` +[Playground-Example](https://metafacture.org/playground/?example=call+macro) + ##### `copy_field` Copies a field from an existing field. @@ -289,6 +305,9 @@ Copies a field from an existing field. copy_field("", "") ``` +[Playground-Example](https://metafacture.org/playground/?example=copy+field) + + ##### `format` Replaces the value with a formatted (`sprintf`-like) version. @@ -321,6 +340,9 @@ Moves a field from an existing field. Can be used to rename a field. move_field("", "") ``` +[Playground-Example](https://metafacture.org/playground/?example=move+field) + + ##### `parse_text` Parses a text into an array or hash of values. @@ -352,6 +374,8 @@ paste("my.string", "~Hi", "a", "~how are you?") # "my.string": "Hi eeny how are you?" ``` +[Playground-Example](https://metafacture.org/playground/?example=paste) + ##### `print_record` Prints the current record as JSON either to standard output or to a file. @@ -401,6 +425,8 @@ Removes a field. remove_field("") ``` +[Playground-Example](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. @@ -409,6 +435,8 @@ Replaces a regular expression pattern in subfield names of a field. Does not cha rename("", "", "") ``` +[Playground-Example](https://metafacture.org/playground/?example=rename) + ##### `retain` Deletes all fields except the ones listed (incl. subfields). @@ -417,6 +445,8 @@ Deletes all fields except the ones listed (incl. subfields). retain(""[, ...]) ``` +[Playground-Example](https://metafacture.org/playground/?example=retain) + ##### `set_array` Creates a new array (with optional values). @@ -426,6 +456,8 @@ set_array("") set_array("", ""[, ...]) ``` +[Playground-Example](https://metafacture.org/playground/?example=set+array) + ##### `set_field` Creates (or replaces) a field with a defined value. @@ -465,6 +497,8 @@ Deletes empty fields, arrays and objects. vacuum() ``` +[Playground-Example](https://metafacture.org/playground/?example=vacuum) + #### Field-level functions ##### `append` @@ -475,6 +509,8 @@ Adds a string at the end of a field value. append("", "") ``` +[Playground-Example](https://metafacture.org/playground/?example=append) + ##### `capitalize` Upcases the first character in a field value. @@ -483,6 +519,8 @@ Upcases the first character in a field value. capitalize("") ``` +[Playground-Example](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. @@ -499,6 +537,8 @@ Downcases all characters in a field value. downcase("") ``` +[Playground-Example](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. @@ -515,6 +555,8 @@ Flattens a nested array field. flatten("") ``` +[Playground-Example](https://metafacture.org/playground/?example=flatten) + ##### `from_json` Replaces the string with its JSON deserialization. @@ -549,6 +591,8 @@ Options: isbn(""[, to: ""][, verify_check_digit: ""][, error_string: ""]) ``` +[Playground-Example](https://metafacture.org/playground/?example=isbn) + ##### `join_field` Joins an array of strings into a single string. @@ -557,6 +601,8 @@ Joins an array of strings into a single string. join_field("", "") ``` +[Playground-Example](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. @@ -624,6 +670,8 @@ Adds a string at the beginning of a field value. prepend("", "") ``` +[Playground-Example](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 (`${}`). @@ -632,6 +680,8 @@ Replaces a regular expression pattern in field values with a replacement string. replace_all("", "", "") ``` +[Playground-Example](https://metafacture.org/playground/?example=replace+all) + ##### `reverse` Reverses the character order of a string or the element order of an array. @@ -650,6 +700,8 @@ sort_field("", reverse: "true") sort_field("", numeric: "true") ``` +[Playground-Example](https://metafacture.org/playground/?example=sort+field) + ##### `split_field` Splits a string into an array and replaces the field value with this array. @@ -658,6 +710,8 @@ Splits a string into an array and replaces the field value with this array. split_field("", "") ``` +[Playground-Example](https://metafacture.org/playground/?example=split+field) + ##### `substring` Replaces a string with its substring as defined by the start position (offset) and length. @@ -695,6 +749,8 @@ Deletes whitespace at the beginning and the end of a field value. trim("") ``` +[Playground-Example](https://metafacture.org/playground/?example=trim) + ##### `uniq` Deletes duplicate values in an array. @@ -703,6 +759,9 @@ Deletes duplicate values in an array. uniq("") ``` +[Playground-Example](https://metafacture.org/playground/?example=uniq) + + ##### `upcase` Upcases all characters in a field value. @@ -711,6 +770,8 @@ Upcases all characters in a field value. upcase("") ``` +[Playground-Example](https://metafacture.org/playground/?example=upcase) + ##### `uri_encode` Encodes a field value as URI. Aka percent-encoding. @@ -742,6 +803,8 @@ if end ``` +[Playground-Example](https://metafacture.org/playground/?example=reject) + ### Binds #### `do list` @@ -754,6 +817,8 @@ do list(path: "") end ``` +[Playground-Example](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: @@ -764,6 +829,8 @@ do list(path: "", "var": "") end ``` +[Playground-Example](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). @@ -797,6 +864,8 @@ do once() end ``` +[Playground-Example](https://metafacture.org/playground/?example=do+once) + In order to execute multiple blocks only once, tag them with unique identifiers: ```perl @@ -833,6 +902,8 @@ end call_macro(""[, ...]) ``` +[Playground-Example](https://metafacture.org/playground/?example=do+pu+macro) + ### Conditionals Conditionals start with `if` in case of affirming the condition or `unless` rejecting the condition.