Class: Relaton::Iso::Docidentifier
- Inherits:
-
Bib::Docidentifier
- Object
- Bib::Docidentifier
- Relaton::Iso::Docidentifier
- Defined in:
- lib/relaton/iso/model/docidentifier.rb
Instance Attribute Summary collapse
-
#pubid ⇒ Object
readonly
Returns the value of attribute pubid.
Instance Method Summary collapse
- #content ⇒ Object
- #content=(value) ⇒ Object
- #exclude_year ⇒ Object
-
#initialize(arg = nil, **kwargs) ⇒ Docidentifier
constructor
A new instance of Docidentifier.
- #original_content ⇒ Object
- #original_content= ⇒ Object
- #remove_date! ⇒ Object
- #remove_part! ⇒ Object
- #remove_stage! ⇒ Object
- #to_all_parts! ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(arg = nil, **kwargs) ⇒ Docidentifier
Returns a new instance of Docidentifier.
10 11 12 13 14 15 16 |
# File 'lib/relaton/iso/model/docidentifier.rb', line 10 def initialize(arg = nil, **kwargs) arg.is_a?(Hash) ? super(arg) : super(**kwargs) # Content may have been set before type during lutaml init. Re-run # the setter so type-dependent parsing (e.g. iso-tc bypass) applies. raw = arg.is_a?(Hash) ? (arg["content"] || arg[:content]) : kwargs[:content] self.content = raw if raw end |
Instance Attribute Details
#pubid ⇒ Object (readonly)
Returns the value of attribute pubid.
8 9 10 |
# File 'lib/relaton/iso/model/docidentifier.rb', line 8 def pubid @pubid end |
Instance Method Details
#content ⇒ Object
60 61 62 63 64 65 |
# File 'lib/relaton/iso/model/docidentifier.rb', line 60 def content return @raw_content if @raw_content return render_pubid(@pubid) if @pubid original_content end |
#content=(value) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/relaton/iso/model/docidentifier.rb', line 21 def content=(value) @pubid = nil @raw_content = nil if type == "iso-tc" && value.is_a?(String) @raw_content = value else parsed = case value when ::Pubid::Iso::Identifier then value when String begin ::Pubid::Iso::Identifier.parse(value) rescue StandardError # Suppress when type is not yet set (lutaml runs the setter # once during init before `type` is assigned, then `initialize` # re-runs it; only the second pass is authoritative). Util.warn "Failed to parse Pubid: #{value}" if type nil end end if parsed @pubid = parsed # TC committee documents have a canonical spelling ("… N1110") # that pubid renders with a space ("… N 1110"). Preserve the # source string (same intent as the iso-tc bypass) while keeping # the parsed pubid for any structural operations. if value.is_a?(String) && parsed.is_a?(::Pubid::Iso::Identifiers::TcDocument) @raw_content = value end elsif value.is_a?(String) @raw_content = value end end send(:original_content=, to_s) end |
#exclude_year ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/relaton/iso/model/docidentifier.rb', line 93 def exclude_year return @raw_content if @raw_content return nil unless @pubid pubid = @pubid.exclude(:date) current = pubid while current.base_identifier current.base_identifier = current.base_identifier.exclude(:date) current = current.base_identifier end pubid end |
#original_content ⇒ Object
19 |
# File 'lib/relaton/iso/model/docidentifier.rb', line 19 alias_method :original_content, :content |
#original_content= ⇒ Object
18 |
# File 'lib/relaton/iso/model/docidentifier.rb', line 18 alias_method :original_content=, :content= |
#remove_date! ⇒ Object
89 90 91 |
# File 'lib/relaton/iso/model/docidentifier.rb', line 89 def remove_date! remove_attr!(:date) end |
#remove_part! ⇒ Object
85 86 87 |
# File 'lib/relaton/iso/model/docidentifier.rb', line 85 def remove_part! remove_attr!(:part) end |
#remove_stage! ⇒ Object
81 82 83 |
# File 'lib/relaton/iso/model/docidentifier.rb', line 81 def remove_stage! remove_attr!(:stage) end |
#to_all_parts! ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/relaton/iso/model/docidentifier.rb', line 71 def to_all_parts! return unless @pubid remove_part! remove_date! remove_stage! @pubid.all_parts = true refresh_content! end |
#to_s ⇒ Object
67 68 69 |
# File 'lib/relaton/iso/model/docidentifier.rb', line 67 def to_s content.to_s end |