Skip to content

Commit

Permalink
Add links to playground for several fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasNx committed Nov 23, 2023
1 parent b129d44 commit 68580f9
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -178,6 +180,8 @@ Defines an external map for [lookup](#lookup) from a file or a URL. Maps with mo
put_filemap("<sourceFile>", "<mapName>", 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 |
Expand Down Expand Up @@ -207,6 +211,8 @@ put_map("<mapName>",
)
```

[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.
Expand All @@ -218,6 +224,8 @@ put_rdfmap("<rdfResource>", "<rdfMapName>", target: "<rdfProperty>")
put_rdfmap("<rdfResource>", "<rdfMapName>", target: "<rdfProperty>", select_language: "<rdfLanguageTag>")
```

[Playground-Example](https://metafacture.org/playground/?example=put_rdfmap)

##### `put_var`

Defines a single global variable that can be referenced with `$[<variableName>]`.
Expand All @@ -226,6 +234,8 @@ Defines a single global variable that can be referenced with `$[<variableName>]`
put_var("<variableName>", "<variableValue>")
```

[Playground-Example](https://metafacture.org/playground/?example=put_var)

##### `put_vars`

Defines multiple global variables that can be referenced with `$[<variableName>]`.
Expand All @@ -237,6 +247,8 @@ put_vars(
)
```

[Playground-Example](https://metafacture.org/playground/?example=put_vars)

#### Record-level functions

##### `add_field`
Expand All @@ -247,6 +259,8 @@ Creates a field with a defined value.
add_field("<targetFieldName>", "<fieldValue>")
```

[Playground-Example](https://metafacture.org/playground/?example=add+field)

##### `array`

Converts a hash/object into an array.
Expand Down Expand Up @@ -281,6 +295,8 @@ end
call_macro("<macroName>"[, <dynamicLocalVariables>...])
```

[Playground-Example](https://metafacture.org/playground/?example=call+macro)

##### `copy_field`

Copies a field from an existing field.
Expand All @@ -289,6 +305,9 @@ Copies a field from an existing field.
copy_field("<sourceField>", "<targetField>")
```

[Playground-Example](https://metafacture.org/playground/?example=copy+field)


##### `format`

Replaces the value with a formatted (`sprintf`-like) version.
Expand Down Expand Up @@ -321,6 +340,9 @@ Moves a field from an existing field. Can be used to rename a field.
move_field("<sourceField>", "<targetField>")
```

[Playground-Example](https://metafacture.org/playground/?example=move+field)


##### `parse_text`

Parses a text into an array or hash of values.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -401,6 +425,8 @@ Removes a field.
remove_field("<sourceField>")
```

[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.
Expand All @@ -409,6 +435,8 @@ Replaces a regular expression pattern in subfield names of a field. Does not cha
rename("<sourceField>", "<regexp>", "<replacement>")
```

[Playground-Example](https://metafacture.org/playground/?example=rename)

##### `retain`

Deletes all fields except the ones listed (incl. subfields).
Expand All @@ -417,6 +445,8 @@ Deletes all fields except the ones listed (incl. subfields).
retain("<sourceField_1>"[, ...])
```

[Playground-Example](https://metafacture.org/playground/?example=retain)

##### `set_array`

Creates a new array (with optional values).
Expand All @@ -426,6 +456,8 @@ set_array("<targetFieldName>")
set_array("<targetFieldName>", "<value_1>"[, ...])
```

[Playground-Example](https://metafacture.org/playground/?example=set+array)

##### `set_field`

Creates (or replaces) a field with a defined value.
Expand Down Expand Up @@ -465,6 +497,8 @@ Deletes empty fields, arrays and objects.
vacuum()
```

[Playground-Example](https://metafacture.org/playground/?example=vacuum)

#### Field-level functions

##### `append`
Expand All @@ -475,6 +509,8 @@ Adds a string at the end of a field value.
append("<sourceField>", "<appendString>")
```

[Playground-Example](https://metafacture.org/playground/?example=append)

##### `capitalize`

Upcases the first character in a field value.
Expand All @@ -483,6 +519,8 @@ Upcases the first character in a field value.
capitalize("<sourceField>")
```

[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.
Expand All @@ -499,6 +537,8 @@ Downcases all characters in a field value.
downcase("<sourceField>")
```

[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.
Expand All @@ -515,6 +555,8 @@ Flattens a nested array field.
flatten("<sourceField>")
```

[Playground-Example](https://metafacture.org/playground/?example=flatten)

##### `from_json`

Replaces the string with its JSON deserialization.
Expand Down Expand Up @@ -549,6 +591,8 @@ Options:
isbn("<sourceField>"[, to: "<isbnFormat>"][, verify_check_digit: "<boolean>"][, error_string: "<errorValue>"])
```

[Playground-Example](https://metafacture.org/playground/?example=isbn)

##### `join_field`

Joins an array of strings into a single string.
Expand All @@ -557,6 +601,8 @@ Joins an array of strings into a single string.
join_field("<sourceField>", "<separator>")
```

[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.
Expand Down Expand Up @@ -624,6 +670,8 @@ Adds a string at the beginning of a field value.
prepend("<sourceField>", "<prependString>")
```

[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 (`$<number>`) or name (`${<name>}`).
Expand All @@ -632,6 +680,8 @@ Replaces a regular expression pattern in field values with a replacement string.
replace_all("<sourceField>", "<regexp>", "<replacement>")
```

[Playground-Example](https://metafacture.org/playground/?example=replace+all)

##### `reverse`

Reverses the character order of a string or the element order of an array.
Expand All @@ -650,6 +700,8 @@ sort_field("<sourceField>", reverse: "true")
sort_field("<sourceField>", 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.
Expand All @@ -658,6 +710,8 @@ Splits a string into an array and replaces the field value with this array.
split_field("<sourceField>", "<separator>")
```

[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.
Expand Down Expand Up @@ -695,6 +749,8 @@ Deletes whitespace at the beginning and the end of a field value.
trim("<sourceField>")
```

[Playground-Example](https://metafacture.org/playground/?example=trim)

##### `uniq`

Deletes duplicate values in an array.
Expand All @@ -703,6 +759,9 @@ Deletes duplicate values in an array.
uniq("<sourceField>")
```

[Playground-Example](https://metafacture.org/playground/?example=uniq)


##### `upcase`

Upcases all characters in a field value.
Expand All @@ -711,6 +770,8 @@ Upcases all characters in a field value.
upcase("<sourceField>")
```

[Playground-Example](https://metafacture.org/playground/?example=upcase)

##### `uri_encode`

Encodes a field value as URI. Aka percent-encoding.
Expand Down Expand Up @@ -742,6 +803,8 @@ if <condition>
end
```

[Playground-Example](https://metafacture.org/playground/?example=reject)

### Binds

#### `do list`
Expand All @@ -754,6 +817,8 @@ do list(path: "<sourceField>")
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:
Expand All @@ -764,6 +829,8 @@ do list(path: "<sourceField>", "var": "<variableName>")
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).
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -833,6 +902,8 @@ end
call_macro("<macroName>"[, <dynamicLocalVariables>...])
```

[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.
Expand Down

0 comments on commit 68580f9

Please sign in to comment.