Class: Relaton::Bib::ICS
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- Relaton::Bib::ICS
- Defined in:
- lib/relaton/bib/model/ics.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#code=(val) ⇒ Object
When code is assigned, eagerly populate text from Isoics if no explicit text has been set.
-
#text ⇒ Object
Returns the explicit text if set, else the Isoics description for
code. -
#using_default_for(attribute_name) ⇒ Object
When the deserializer reaches the end of the XML element and records that
was absent, it calls using_default_for(:text)to mark the attribute as default-valued (suppressing serialization).
Instance Method Details
#code=(val) ⇒ Object
When code is assigned, eagerly populate text from Isoics if no
explicit text has been set. Going through the public writer
registers the value with the lutaml-model value_set_for tracker
so the attribute is emitted on serialization.
27 28 29 30 31 32 33 34 |
# File 'lib/relaton/bib/model/ics.rb', line 27 def code=(val) super return unless val.is_a?(String) && !val.empty? return if @text.is_a?(String) && !@text.empty? description = Isoics.fetch(val)&.description self.text = description if description end |
#text ⇒ Object
Returns the explicit text if set, else the Isoics description for
code. Kept for consumers that read .text directly.
17 18 19 20 21 |
# File 'lib/relaton/bib/model/ics.rb', line 17 def text return @text if @text.is_a?(String) && !@text.empty? Isoics.fetch(code)&.description if code.is_a?(String) && !code.empty? end |
#using_default_for(attribute_name) ⇒ Object
When the deserializer reaches the end of the XML element and
records that using_default_for(:text)
to mark the attribute as default-valued (suppressing serialization).
Refuse that mark if we've already populated text from Isoics so the
value survives round-trip. See #112.
41 42 43 44 45 46 |
# File 'lib/relaton/bib/model/ics.rb', line 41 def using_default_for(attribute_name) return if attribute_name == :text && @text.is_a?(String) && !@text.empty? super end |