@@ -18,27 +18,11 @@ public data class Resource(
1818 */
1919 val article : Element ? = null ,
2020
21- /* *
22- * Text fields extracted from this resource, stored as key-value pairs. It is recommended to use well-defined keys
23- * from [com.chimbori.crux.Fields] for all standard fields. Custom fields are also supported, in case none of the
24- * pre-defined keys are applicable.
25- */
26- val fields : Map <String , String ?> = emptyMap(),
27-
28- /* *
29- * URL fields extracted from this resource. Storing these as key-value pairs of [HttpUrl]s avoids re-parsing the same
30- * URLs multiple times. URLs can also be retrieved as strings via the [get] indexed accessor.
31- */
32- val urls : Map <String , HttpUrl ?> = emptyMap(),
33-
3421 /* * A holder for any kind of custom objects that library users may want to use. */
35- val objects : Map <String , Any ?> = emptyMap(),
22+ val metadata : Map <String , Any ?> = emptyMap(),
3623) {
37- /* *
38- * @return value of a named field. If there’s no named [String] field corresponding to this key in [Resource.fields],
39- * but a [HttpUrl] exists in [Resource.urls], the latter will be stringified and returned instead.
40- */
41- public operator fun get (key : String ): String? = fields[key] ? : urls[key]?.toString()
24+ /* * @return value of a named field in [Resource.metadata]. */
25+ public operator fun get (key : String ): Any? = metadata[key]
4226
4327 /* *
4428 * Merges non-null fields from another [Resource] with this object, and returns a new immutable object. Prefer to use
@@ -48,19 +32,12 @@ public data class Resource(
4832 url = anotherResource?.url ? : url,
4933 document = anotherResource?.document ? : document,
5034 article = anotherResource?.article ? : article,
51- fields = if (anotherResource?.fields == null ) fields else fields + anotherResource.fields,
52- urls = if (anotherResource?.urls == null ) urls else urls + anotherResource.urls,
53- objects = if (anotherResource?.objects == null ) objects else objects + anotherResource.objects,
35+ metadata = if (anotherResource?.metadata == null ) metadata else metadata + anotherResource.metadata,
5436 )
5537
56- /* *
57- * Removes an immutable copy of this [Resource] that only contains non-null values for each key in both [fields]
58- * and [urls].
59- */
38+ /* * Removes an immutable copy of this [Resource] that only contains non-null values for each key in [metadata]. */
6039 public fun removeNullValues (): Resource = copy(
61- fields = fields.filterValues { ! it.isNullOrBlank() },
62- urls = urls.filterValues { it != null },
63- objects = objects.filterValues { it != null },
40+ metadata = metadata.filterValues { it != null },
6441 )
6542
6643 /* * For any potential extension functions to be defined on the companion object. */
0 commit comments