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.
8 9 10 11 12 13 14 |
# File 'lib/relaton/iso/model/docidentifier.rb', line 8 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.
6 7 8 |
# File 'lib/relaton/iso/model/docidentifier.rb', line 6 def pubid @pubid end |
Instance Method Details
#content ⇒ Object
48 49 50 51 52 53 |
# File 'lib/relaton/iso/model/docidentifier.rb', line 48 def content return @raw_content if @raw_content return render_pubid(@pubid) if @pubid original_content end |
#content=(value) ⇒ Object
19 20 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 |
# File 'lib/relaton/iso/model/docidentifier.rb', line 19 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 Util.warn "Failed to parse Pubid: #{value}" 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
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/relaton/iso/model/docidentifier.rb', line 81 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
17 |
# File 'lib/relaton/iso/model/docidentifier.rb', line 17 alias_method :original_content, :content |
#original_content= ⇒ Object
16 |
# File 'lib/relaton/iso/model/docidentifier.rb', line 16 alias_method :original_content=, :content= |
#remove_date! ⇒ Object
77 78 79 |
# File 'lib/relaton/iso/model/docidentifier.rb', line 77 def remove_date! remove_attr!(:year) end |
#remove_part! ⇒ Object
73 74 75 |
# File 'lib/relaton/iso/model/docidentifier.rb', line 73 def remove_part! remove_attr!(:part) end |
#remove_stage! ⇒ Object
69 70 71 |
# File 'lib/relaton/iso/model/docidentifier.rb', line 69 def remove_stage! remove_attr!(:stage) end |
#to_all_parts! ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/relaton/iso/model/docidentifier.rb', line 59 def to_all_parts! return unless @pubid remove_part! remove_date! remove_stage! @pubid.all_parts = true refresh_content! end |
#to_s ⇒ Object
55 56 57 |
# File 'lib/relaton/iso/model/docidentifier.rb', line 55 def to_s content.to_s end |