chore: add example specs for custom adapters #323
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is for #322 .
This PR provides two sample custom serialization adapter implementations (in pseudocode):
The BibTeX implementation is more complete. The vObject implementation does parse simple vCards but as the vObject schema is much more complex it is incomplete.
Custom serialization adapter implementation
The user is meant to provide the following:
Mapping
class that stores a set of mappings for the serialization formatMappingRule
class, that defines how the mappings work to the target format's elements (e.g. BibTeX has "field", "citekey" and "type key". vObject has "component", "property", "value", etc)Document
class (an instance of raw data to parse, e.g. we haveJsonDocument
) (user can also specify smaller componentsAdapter
class that links the Document and Mapping and to register the{type} do #...
blockThe following content is AI-generated that describes from the content the requirements I've listed above.
BibTeX adapter
spec/lutaml/model/custom_bibtex_adapter_spec.rb
This extension adds support for BibTeX format serialization and deserialization to Lutaml::Model. While BibTeX is traditionally used for academic citations, its structured format makes it suitable for storing various types of information models.
Key Benefits of BibTeX Format
Basic Setup
To use BibTeX format in your model:
Include necessary field classes based on your needs:
BibtexFieldAuthor
- For handling names (authors, maintainers, manufacturers)BibtexFieldYear
- For handling dates and rangesBibtexFieldPage
- For handling numeric rangesDefine your model class inheriting from
Lutaml::Model::Serializable
Register BibTeX format:
bibtex do
block:Mapping Methods
The bibtex block supports these mapping methods:
map_entry_type
: Maps the entry type (e.g., @Article, @book)map_citekey
: Maps the unique identifiermap_field
: Maps fields to model attributesOptions:
to
: Target attribute namerender_nil
: Whether to render nil values (default: false)Examples
1. Traditional Academic Citation
Usage:
2. Software Components Registry
BibTeX's structured format works well for tracking software components:
3. Equipment Inventory
4. Recipe Database
vObject adapter
spec/lutaml/model/custom_vobject_adapter_spec.rb
This module provides support for serializing and deserializing models to/from vObject format, a text-based data format used by standards like vCard and iCalendar.
Basic Usage
To use vObject serialization in your models:
Creating Custom Components
For non-standardized vObject components:
Custom Properties
Define custom properties with parameters:
Value Types
Support for different value types:
Text
(default)URI
Binary
(Base64)Boolean
Integer
Float
UTC-Offset
Language-Tag
IsoDateAndOrTime
Custom Value Types
Create custom value types by extending
VobjectValueType::Base
:Structured Values
For properties with multiple fields:
Registration
Register your custom format:
Component Types
Four types of elements are supported:
:component
- Container components like VCARD:property
- Properties with values and parameters:property_parameter
- Parameters for properties:property_group
- Grouping of related properties