Class: Newsmlg2::NarModel

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/newsmlg2/nar_model.rb

Overview

Base class for every NewsML-G2 (NAR namespace) model. Binds the NAR namespace once so subclasses only declare their element name and mappings, and provides the compact declaration DSL (xml_attributes, xml_element, xml_content) used by model classes and Base group mixins alike.

Subclass skeleton:

class ItemMeta < Newsmlg2::NarModel
include Base::ItemManagementGroup   # shared XSD element group
xml do
  element "itemMeta"                # this class's element name
end
end

lutaml-model accumulates xml mappings across included modules, superclass mappings and the class's own xml block, so group mixins merge in include order and serialized child order follows declaration order.

Direct Known Subclasses

AltLoc, AnyItem, Assert, Catalog, CatalogContainer, CatalogRef, Channel, ConceptSet, ContentMeta, ContentMetaAcD, ContentMetaCat, ContentSet, Delivery, DerivedFromValue, Group, GroupRef, GroupSet, Header, Hop, HopHistory, InlineData, InlineXML, ItemCount, ItemMeta, ItemSet, NewsContentCharacteristicsElement, NewsCoverage, NewsCoverageSet, NewsMessage, PartMeta, Planning, Priority, PubHistory, Published, RegionDelim, RemoteContent, SameAsScheme, Scheme, SchemeMeta, StringType, TimeDelim, Types::A, Types::Address, Types::Affiliation, Types::AltRep, Types::ApproximateDateTimePropType, Types::BlockType, Types::Br, Types::Concept, Types::ContactInfoType, Types::DateOptTimePropType, Types::DateTimeOrNullPropType, Types::DateTimePropType, Types::Dates, Types::ElectronicAddressTechType, Types::ElectronicAddressType, Types::Event, Types::EventDetails, Types::EventDuration, Types::EventNewsCoverage, Types::Events, Types::ExRule, Types::FileName, Types::Flex1PropType, Types::FlexGeoAreaPropType, Types::FlexLocationPropType, Types::FlexPOIPropType, Types::FlexPartyPropType, Types::FlexPersonPropType, Types::FlexProp2Type, Types::FlexPropType, Types::GeoAreaCircle, Types::GeoAreaDetails, Types::GeoAreaLine, Types::GeoAreaPolygon, Types::GeoCoordinatesType, Types::HasInstrument, Types::Hash, Types::HierarchyInfo, Types::Icon, Types::Inline, Types::IntlStringType, Types::IntlStringType2, Types::Label1Type, Types::Language, Types::Link1Type, Types::ObjectDetails, Types::OrganisationDetails, Types::OrigRep, Types::POIDetails, Types::PersonDetails, Types::QCodePropType, Types::RRule, Types::Rating, Types::Rb, Types::RightsExpressionData, Types::RightsExpressionXML, Types::RightsInfo, Types::Rp, Types::Rt, Types::Ruby, Types::Span, Types::TruncatedDateTimePropType, Types::Urgency, Types::UserInteraction, Types::Web

Class Method Summary collapse

Class Method Details

.lutaml_default_registerObject

Resolve registry symbol types (e.g. ItemSet's :"newsItem") in the Newsmlg2 context for direct from_xml/to_xml calls.



23
24
25
# File 'lib/newsmlg2/nar_model.rb', line 23

def self.lutaml_default_register
  Newsmlg2::Configuration::CONTEXT_ID
end

.xml_attributes(*names, **xml_names) ⇒ Object

Declares string attributes together with their XML attribute mappings. Positional names use the Ruby name as the wire name; keyword pairs map a Ruby name to a different wire name (e.g. class_attr: "class").



36
37
38
39
# File 'lib/newsmlg2/nar_model.rb', line 36

def xml_attributes(*names, **xml_names)
  names.each { |name| xml_string_attribute(name, name.to_s) }
  xml_names.each { |name, xml_name| xml_string_attribute(name, xml_name.to_s) }
end

.xml_content(collection: false) ⇒ Object

Declares the element's text-content attribute. Use collection: true for mixed-content models where text interleaves with child elements.



57
58
59
60
# File 'lib/newsmlg2/nar_model.rb', line 57

def xml_content(collection: false)
  attribute :text, :string, collection: collection
  xml { map_content to: :text }
end

.xml_element(ruby_name, xml: ruby_name.to_s, type: :string, collection: false) ⇒ Object

Declares a child element attribute together with its XML element mapping. type may be a class, a string class name (preferred inside Base group mixins to avoid autoload cycles) or a lutaml-model type.



50
51
52
53
# File 'lib/newsmlg2/nar_model.rb', line 50

def xml_element(ruby_name, xml: ruby_name.to_s, type: :string, collection: false)
  attribute ruby_name, type, collection: collection
  xml { map_element xml.to_s, to: ruby_name }
end

.xml_lang_attributeObject

Declares the W3C xml:lang attribute (BCP 47 language tag).



42
43
44
45
# File 'lib/newsmlg2/nar_model.rb', line 42

def xml_lang_attribute
  attribute :xml_lang, Newsmlg2::Types::XmlLang
  xml { map_attribute 'lang', to: :xml_lang }
end

.xml_root_nameObject

The XML element name this class serializes to, or nil for types that only appear as nested children.



64
65
66
# File 'lib/newsmlg2/nar_model.rb', line 64

def xml_root_name
  mappings[:xml]&.root_element
end