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
53 54 55 56 57 58 |
# File 'lib/relaton/iso/model/docidentifier.rb', line 53 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 |
# 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::Base 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 elsif value.is_a?(String) @raw_content = value end end send(:original_content=, to_s) end |
#exclude_year ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/relaton/iso/model/docidentifier.rb', line 86 def exclude_year return @raw_content if @raw_content return nil unless @pubid pubid = @pubid.exclude(:year) current = pubid while current.base current.base = current.base.exclude(:year) current = current.base 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
82 83 84 |
# File 'lib/relaton/iso/model/docidentifier.rb', line 82 def remove_date! remove_attr!(:year) end |
#remove_part! ⇒ Object
78 79 80 |
# File 'lib/relaton/iso/model/docidentifier.rb', line 78 def remove_part! remove_attr!(:part) end |
#remove_stage! ⇒ Object
74 75 76 |
# File 'lib/relaton/iso/model/docidentifier.rb', line 74 def remove_stage! remove_attr!(:stage) end |
#to_all_parts! ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/relaton/iso/model/docidentifier.rb', line 64 def to_all_parts! return unless @pubid remove_part! remove_date! remove_stage! @pubid.all_parts = true refresh_content! end |
#to_s ⇒ Object
60 61 62 |
# File 'lib/relaton/iso/model/docidentifier.rb', line 60 def to_s content.to_s end |