Class: RelatonIsoBib::StructuredIdentifier
- Inherits:
-
Object
- Object
- RelatonIsoBib::StructuredIdentifier
- Defined in:
- lib/relaton_iso_bib/structured_identifier.rb
Overview
Document structured identifier.
Instance Attribute Summary collapse
- #part ⇒ Integer? readonly
- #project_number ⇒ String readonly
- #subpart ⇒ Integer? readonly
- #tc_document_number ⇒ Integer? readonly
- #type ⇒ String? readonly
Instance Method Summary collapse
- #all_parts ⇒ Object
- #id ⇒ Object
-
#initialize(**args) ⇒ StructuredIdentifier
constructor
A new instance of StructuredIdentifier.
- #presence? ⇒ Boolean
- #remove_date ⇒ Object
-
#remove_part ⇒ Object
in docid manipulations, assume ISO as the default: id-part:year.
- #to_asciibib(prefix = "") ⇒ String
- #to_hash ⇒ Hash
- #to_xml(builder) ⇒ Object
Constructor Details
#initialize(**args) ⇒ StructuredIdentifier
Returns a new instance of StructuredIdentifier.
24 25 26 27 28 29 30 |
# File 'lib/relaton_iso_bib/structured_identifier.rb', line 24 def initialize(**args) @tc_document_number = args[:tc_document_number] @project_number = args[:project_number] @part = args[:part] @subpart = args[:subpart] @type = args[:type] end |
Instance Attribute Details
#part ⇒ Integer? (readonly)
11 12 13 |
# File 'lib/relaton_iso_bib/structured_identifier.rb', line 11 def part @part end |
#project_number ⇒ String (readonly)
8 9 10 |
# File 'lib/relaton_iso_bib/structured_identifier.rb', line 8 def project_number @project_number end |
#subpart ⇒ Integer? (readonly)
14 15 16 |
# File 'lib/relaton_iso_bib/structured_identifier.rb', line 14 def subpart @subpart end |
#tc_document_number ⇒ Integer? (readonly)
5 6 7 |
# File 'lib/relaton_iso_bib/structured_identifier.rb', line 5 def tc_document_number @tc_document_number end |
#type ⇒ String? (readonly)
17 18 19 |
# File 'lib/relaton_iso_bib/structured_identifier.rb', line 17 def type @type end |
Instance Method Details
#all_parts ⇒ Object
52 53 54 |
# File 'lib/relaton_iso_bib/structured_identifier.rb', line 52 def all_parts @project_number = "#{@project_number} (all parts)" end |
#id ⇒ Object
56 57 58 |
# File 'lib/relaton_iso_bib/structured_identifier.rb', line 56 def id project_number end |
#presence? ⇒ Boolean
102 103 104 |
# File 'lib/relaton_iso_bib/structured_identifier.rb', line 102 def presence? true end |
#remove_date ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/relaton_iso_bib/structured_identifier.rb', line 44 def remove_date if @type == "Chinese Standard" @project_number.sub!(/-[12]\d\d\d/, "") else @project_number.sub!(/:[12]\d\d\d/, "") end end |
#remove_part ⇒ Object
in docid manipulations, assume ISO as the default: id-part:year
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/relaton_iso_bib/structured_identifier.rb', line 33 def remove_part @part = nil @subpart = nil @project_number = case @type when "Chinese Standard" @project_number.sub(/\.\d+/, "") else @project_number = @project_number.sub(/-\d+/, "") end end |
#to_asciibib(prefix = "") ⇒ String
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/relaton_iso_bib/structured_identifier.rb', line 86 def to_asciibib(prefix = "") # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength pref = prefix.empty? ? prefix : "#{prefix}." pref += "structured_identifier" out = "" if tc_document_number out += "#{pref}.tc_document_number:: #{tc_document_number}\n" end if project_number out += "#{pref}.project_number:: #{project_number}\n" end out += "#{pref}.part:: #{part}\n" if part out += "#{pref}.subpart:: #{subpart}\n" if subpart out += "#{pref}.type:: #{type}\n" if type out end |
#to_hash ⇒ Hash
74 75 76 77 78 79 80 81 82 |
# File 'lib/relaton_iso_bib/structured_identifier.rb', line 74 def to_hash # rubocop:disable Metrics/AbcSize hash = {} hash["tc_document_number"] = tc_document_number if tc_document_number hash["project_number"] = project_number if project_number hash["part"] = part if part hash["subpart"] = subpart if subpart hash["type"] = type if type hash end |
#to_xml(builder) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/relaton_iso_bib/structured_identifier.rb', line 61 def to_xml(builder) # rubocop:disable Metrics/AbcSize xml = builder.structuredidentifier do pn = builder.send :"project-number", project_number pn[:part] = part if part pn[:subpart] = subpart if subpart if tc_document_number builder.send :"tc-document-number", tc_document_number end end xml[:type] = type if type end |