Skip to content

Commit 689f41e

Browse files
authored
Update Fix-function-and-Cookbook.md
This brings the documentation up to the status of metafacture fix release 1.0.0 https://github.com/metafacture/metafacture-fix/releases/tag/1.0.0
1 parent 7c3f438 commit 689f41e

File tree

1 file changed

+75
-1
lines changed

1 file changed

+75
-1
lines changed

Fix-function-and-Cookbook.md

+75-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
This page is a replication of the passage of the Fix Readme.md.
1+
This page is a replication of the passage of the Fix Readme.md. Status: [Fix Release 1.0.0](https://github.com/metafacture/metafacture-fix/releases/tag/1.0.0)
22

33
## Functions and cookbook
44

@@ -66,6 +66,8 @@ Does nothing. It is used for benchmarking in Catmandu.
6666
nothing()
6767
```
6868

69+
[Example in Playground](https://metafacture.org/playground/?example=nothing)
70+
6971
##### `put_filemap`
7072

7173
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.
@@ -74,6 +76,8 @@ Defines an external map for [lookup](#lookup) from a file or a URL. Maps with mo
7476
put_filemap("<sourceFile>", "<mapName>", sep_char: "\t")
7577
```
7678

79+
[Example in Playground](https://metafacture.org/playground/?example=put_filemap)
80+
7781
The separator (`sep_char`) will vary depending on the source file, e.g.:
7882

7983
| Type | Separator |
@@ -103,6 +107,8 @@ put_map("<mapName>",
103107
)
104108
```
105109

110+
[Example in Playground](https://metafacture.org/playground/?example=put_map)
111+
106112
##### `put_rdfmap`
107113

108114
Defines an external RDF map for lookup from a file or an HTTP(S) resource.
@@ -114,6 +120,8 @@ put_rdfmap("<rdfResource>", "<rdfMapName>", target: "<rdfProperty>")
114120
put_rdfmap("<rdfResource>", "<rdfMapName>", target: "<rdfProperty>", select_language: "<rdfLanguageTag>")
115121
```
116122

123+
[Example in Playground](https://metafacture.org/playground/?example=put_rdfmap)
124+
117125
##### `put_var`
118126

119127
Defines a single global variable that can be referenced with `$[<variableName>]`.
@@ -122,6 +130,8 @@ Defines a single global variable that can be referenced with `$[<variableName>]`
122130
put_var("<variableName>", "<variableValue>")
123131
```
124132

133+
[Example in Playground](https://metafacture.org/playground/?example=put_var)
134+
125135
##### `put_vars`
126136

127137
Defines multiple global variables that can be referenced with `$[<variableName>]`.
@@ -133,6 +143,8 @@ put_vars(
133143
)
134144
```
135145

146+
[Example in Playground](https://metafacture.org/playground/?example=put_vars)
147+
136148
#### Record-level functions
137149

138150
##### `add_field`
@@ -143,6 +155,8 @@ Creates a field with a defined value.
143155
add_field("<targetFieldName>", "<fieldValue>")
144156
```
145157

158+
[Example in Playground](https://metafacture.org/playground/?example=add_field)
159+
146160
##### `array`
147161

148162
Converts a hash/object into an array.
@@ -177,6 +191,8 @@ end
177191
call_macro("<macroName>"[, <dynamicLocalVariables>...])
178192
```
179193

194+
[Example in Playground](https://metafacture.org/playground/?example=call_macro)
195+
180196
##### `copy_field`
181197

182198
Copies a field from an existing field.
@@ -185,6 +201,9 @@ Copies a field from an existing field.
185201
copy_field("<sourceField>", "<targetField>")
186202
```
187203

204+
[Example in Playground](https://metafacture.org/playground/?example=copy_field)
205+
206+
188207
##### `format`
189208

190209
Replaces the value with a formatted (`sprintf`-like) version.
@@ -217,6 +236,9 @@ Moves a field from an existing field. Can be used to rename a field.
217236
move_field("<sourceField>", "<targetField>")
218237
```
219238

239+
[Example in Playground](https://metafacture.org/playground/?example=move_field)
240+
241+
220242
##### `parse_text`
221243

222244
Parses a text into an array or hash of values.
@@ -248,6 +270,8 @@ paste("my.string", "~Hi", "a", "~how are you?")
248270
# "my.string": "Hi eeny how are you?"
249271
```
250272

273+
[Example in Playground](https://metafacture.org/playground/?example=paste)
274+
251275
##### `print_record`
252276

253277
Prints the current record as JSON either to standard output or to a file.
@@ -297,6 +321,8 @@ Removes a field.
297321
remove_field("<sourceField>")
298322
```
299323

324+
[Example in Playground](https://metafacture.org/playground/?example=remove_field)
325+
300326
##### `rename`
301327

302328
Replaces a regular expression pattern in subfield names of a field. Does not change the name of the source field itself.
@@ -305,6 +331,8 @@ Replaces a regular expression pattern in subfield names of a field. Does not cha
305331
rename("<sourceField>", "<regexp>", "<replacement>")
306332
```
307333

334+
[Example in Playground](https://metafacture.org/playground/?example=rename)
335+
308336
##### `retain`
309337

310338
Deletes all fields except the ones listed (incl. subfields).
@@ -313,6 +341,8 @@ Deletes all fields except the ones listed (incl. subfields).
313341
retain("<sourceField_1>"[, ...])
314342
```
315343

344+
[Example in Playground](https://metafacture.org/playground/?example=retain)
345+
316346
##### `set_array`
317347

318348
Creates a new array (with optional values).
@@ -322,6 +352,8 @@ set_array("<targetFieldName>")
322352
set_array("<targetFieldName>", "<value_1>"[, ...])
323353
```
324354

355+
[Example in Playground](https://metafacture.org/playground/?example=set_array)
356+
325357
##### `set_field`
326358

327359
Creates (or replaces) a field with a defined value.
@@ -361,6 +393,8 @@ Deletes empty fields, arrays and objects.
361393
vacuum()
362394
```
363395

396+
[Example in Playground](https://metafacture.org/playground/?example=vacuum)
397+
364398
#### Field-level functions
365399

366400
##### `append`
@@ -371,6 +405,8 @@ Adds a string at the end of a field value.
371405
append("<sourceField>", "<appendString>")
372406
```
373407

408+
[Example in Playground](https://metafacture.org/playground/?example=append)
409+
374410
##### `capitalize`
375411

376412
Upcases the first character in a field value.
@@ -379,6 +415,8 @@ Upcases the first character in a field value.
379415
capitalize("<sourceField>")
380416
```
381417

418+
[Example in Playground](https://metafacture.org/playground/?example=capitalize)
419+
382420
##### `count`
383421

384422
Counts the number of elements in an array or a hash and replaces the field value with this number.
@@ -395,6 +433,8 @@ Downcases all characters in a field value.
395433
downcase("<sourceField>")
396434
```
397435

436+
[Example in Playground](https://metafacture.org/playground/?example=downcase)
437+
398438
##### `filter`
399439

400440
Only keeps field values that match the regular expression pattern. Works only with array of strings/repeated fields.
@@ -411,6 +451,8 @@ Flattens a nested array field.
411451
flatten("<sourceField>")
412452
```
413453

454+
[Example in Playground](https://metafacture.org/playground/?example=flatten)
455+
414456
##### `from_json`
415457

416458
Replaces the string with its JSON deserialization.
@@ -445,6 +487,8 @@ Options:
445487
isbn("<sourceField>"[, to: "<isbnFormat>"][, verify_check_digit: "<boolean>"][, error_string: "<errorValue>"])
446488
```
447489

490+
[Example in Playground](https://metafacture.org/playground/?example=isbn)
491+
448492
##### `join_field`
449493

450494
Joins an array of strings into a single string.
@@ -453,6 +497,8 @@ Joins an array of strings into a single string.
453497
join_field("<sourceField>", "<separator>")
454498
```
455499

500+
[Example in Playground](https://metafacture.org/playground/?example=join_field)
501+
456502
##### `lookup`
457503

458504
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.
@@ -520,6 +566,8 @@ Adds a string at the beginning of a field value.
520566
prepend("<sourceField>", "<prependString>")
521567
```
522568

569+
[Example in Playground](https://metafacture.org/playground/?example=prepend)
570+
523571
##### `replace_all`
524572

525573
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>}`).
@@ -528,6 +576,8 @@ Replaces a regular expression pattern in field values with a replacement string.
528576
replace_all("<sourceField>", "<regexp>", "<replacement>")
529577
```
530578

579+
[Example in Playground](https://metafacture.org/playground/?example=replace_all)
580+
531581
##### `reverse`
532582

533583
Reverses the character order of a string or the element order of an array.
@@ -546,6 +596,8 @@ sort_field("<sourceField>", reverse: "true")
546596
sort_field("<sourceField>", numeric: "true")
547597
```
548598

599+
[Example in Playground](https://metafacture.org/playground/?example=sort_field)
600+
549601
##### `split_field`
550602

551603
Splits a string into an array and replaces the field value with this array.
@@ -554,6 +606,8 @@ Splits a string into an array and replaces the field value with this array.
554606
split_field("<sourceField>", "<separator>")
555607
```
556608

609+
[Example in Playground](https://metafacture.org/playground/?example=split_field)
610+
557611
##### `substring`
558612

559613
Replaces a string with its substring as defined by the start position (offset) and length.
@@ -591,6 +645,8 @@ Deletes whitespace at the beginning and the end of a field value.
591645
trim("<sourceField>")
592646
```
593647

648+
[Example in Playground](https://metafacture.org/playground/?example=trim)
649+
594650
##### `uniq`
595651

596652
Deletes duplicate values in an array.
@@ -599,6 +655,9 @@ Deletes duplicate values in an array.
599655
uniq("<sourceField>")
600656
```
601657

658+
[Example in Playground](https://metafacture.org/playground/?example=uniq)
659+
660+
602661
##### `upcase`
603662

604663
Upcases all characters in a field value.
@@ -607,6 +666,8 @@ Upcases all characters in a field value.
607666
upcase("<sourceField>")
608667
```
609668

669+
[Example in Playground](https://metafacture.org/playground/?example=upcase)
670+
610671
##### `uri_encode`
611672

612673
Encodes a field value as URI. Aka percent-encoding.
@@ -638,6 +699,8 @@ if <condition>
638699
end
639700
```
640701

702+
[Example in Playground](https://metafacture.org/playground/?example=reject)
703+
641704
### Binds
642705

643706
#### `do list`
@@ -650,6 +713,8 @@ do list(path: "<sourceField>")
650713
end
651714
```
652715

716+
[Example in Playground](https://metafacture.org/playground/?example=do_list)
717+
653718
Only the current element is accessible in this case (as the root element).
654719

655720
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:
@@ -660,6 +725,8 @@ do list(path: "<sourceField>", "var": "<variableName>")
660725
end
661726
```
662727

728+
[Example in Playground](https://metafacture.org/playground/?example=do_list_with_var)
729+
663730
#### `do list_as`
664731

665732
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).
@@ -693,6 +760,8 @@ do once()
693760
end
694761
```
695762

763+
[Example in Playground](https://metafacture.org/playground/?example=do_once)
764+
696765
In order to execute multiple blocks only once, tag them with unique identifiers:
697766

698767
```perl
@@ -729,6 +798,8 @@ end
729798
call_macro("<macroName>"[, <dynamicLocalVariables>...])
730799
```
731800

801+
[Example in Playground](https://metafacture.org/playground/?example=do_put_macro)
802+
732803
### Conditionals
733804

734805
Conditionals start with `if` in case of affirming the condition or `unless` rejecting the condition.
@@ -865,3 +936,6 @@ Executes the functions if/unless the field value does not match the regular expr
865936

866937
Executes the functions if/unless the string matches the regular expression pattern.
867938

939+
## Xtext
940+
941+
This repo has been originally set up with [Xtext](https://www.eclipse.org/Xtext/) 2.17.0 and Eclipse for Java 2019-03, following [https://www.eclipse.org/Xtext/documentation/104_jvmdomainmodel.html](https://www.eclipse.org/Xtext/documentation/104_jvmdomainmodel.html).

0 commit comments

Comments
 (0)