Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add links to playground for several fixes #339

Merged
merged 4 commits into from
Nov 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
```

[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.
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")
```

[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 |
Expand Down Expand Up @@ -207,6 +211,8 @@ put_map("<mapName>",
)
```

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

[Example in Playground](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>")
```

[Example in Playground](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(
)
```

[Example in Playground](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>")
```

[Example in Playground](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>...])
```

[Example in Playground](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>")
```

[Example in Playground](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>")
```

[Example in Playground](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?"
```

[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.
Expand Down Expand Up @@ -401,6 +425,8 @@ Removes a field.
remove_field("<sourceField>")
```

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

[Example in Playground](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>"[, ...])
```

[Example in Playground](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>"[, ...])
```

[Example in Playground](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()
```

[Example in Playground](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>")
```

[Example in Playground](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>")
```

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

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

[Example in Playground](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>"])
```

[Example in Playground](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>")
```

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

[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 (`$<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>")
```

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

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

[Example in Playground](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>")
```

[Example in Playground](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>")
```

[Example in Playground](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
```

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

### Binds

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

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