Class: Pubid::Bsi::Identifiers::ConsolidatedIdentifier
- Inherits:
-
Base
- Object
- Lutaml::Model::Serializable
- Identifier
- Base
- Pubid::Bsi::Identifiers::ConsolidatedIdentifier
show all
- Defined in:
- lib/pubid/bsi/identifiers/consolidated_identifier.rb
Overview
Consolidated Identifier - contains base document plus supplements Example: “BS 4592-0:2006+A1:2012” = [BS 4592-0:2006, Amendment 1:2012]
Instance Method Summary
collapse
Methods inherited from Identifier
#base_identifier, #eql?, #exclude, #hash, #initialize, #mr_number, #mr_number_with_part, #mr_part, #mr_publisher, #mr_type, #mr_year, #new_edition_of?, polymorphic_name, #render, #resolve_urn_generator, #root, #to_mr_string, #to_supplement_s, #urn_supplement_type, #urn_type_code
Instance Method Details
#date ⇒ Object
130
131
132
133
|
# File 'lib/pubid/bsi/identifiers/consolidated_identifier.rb', line 130
def date
base = identifiers&.first
base.date if base&.class&.attributes&.key?(:date)
end
|
#number ⇒ Object
121
122
123
|
# File 'lib/pubid/bsi/identifiers/consolidated_identifier.rb', line 121
def number
identifiers&.first&.number
end
|
#part ⇒ Object
140
141
142
143
|
# File 'lib/pubid/bsi/identifiers/consolidated_identifier.rb', line 140
def part
base = identifiers&.first
base.part if base&.class&.attributes&.key?(:part)
end
|
#parts ⇒ Object
135
136
137
138
|
# File 'lib/pubid/bsi/identifiers/consolidated_identifier.rb', line 135
def parts
base = identifiers&.first
base.parts if base&.class&.attributes&.key?(:parts)
end
|
#publisher ⇒ Object
Delegate to first identifier (base document)
117
118
119
|
# File 'lib/pubid/bsi/identifiers/consolidated_identifier.rb', line 117
def publisher
identifiers&.first&.publisher
end
|
#to_s(lang: :en, lang_single: false) ⇒ Object
11
12
13
14
15
16
17
18
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/pubid/bsi/identifiers/consolidated_identifier.rb', line 11
def to_s(lang: :en, lang_single: false)
base_id = identifiers.first
result = if base_id.is_a?(Base) && base_id.class.method_defined?(:to_s_without_suffixes)
base_id.to_s_without_suffixes
else
base_str = base_id.to_s
base_str = base_str.sub(/ ExComm \(.*?\)$/, "") .sub(/ ExComm$/, "") .sub(/ - TC$/, "")
.sub(/ PDF$/, "")
.sub(/ \([A-Z][a-z]+\)$/, "")
base_str
end
identifiers[1..].each do |id|
if id.is_a?(Amendment)
if id.amendment_year
sep = id.is_a?(Base) && id.separator ? id.separator : "+"
result += "#{sep}A#{id.amendment_number}:#{id.amendment_year}"
else
result += if id.amendment_number&.match?(/^[A-Z]+$/)
" AMD #{id.amendment_number}"
else
" AMD#{id.amendment_number}"
end
end
elsif id.is_a?(Corrigendum)
sep = id.is_a?(Base) && id.separator ? id.separator : "+"
result += "#{sep}C"
result += id.corrigendum_number.to_s if id.corrigendum_number
result += ":#{id.corrigendum_year}" if id.corrigendum_year
else
result += id.to_s
end
end
if base_id.is_a?(Pubid::Identifier)
base_attrs = base_id.class.attributes
ec = base_attrs.key?(:expert_commentary) ? base_id. : nil
if ec
ect = base_attrs.key?(:expert_commentary_topic) ? base_id. : nil
result += ect ? " ExComm (#{ect})" : " ExComm"
end
tc = base_attrs.key?(:tracked_changes) ? base_id.tracked_changes : nil
result += " - TC" if tc
tl = base_attrs.key?(:translation_lang) ? base_id.translation_lang : nil
if tl
ts_type = base_attrs.key?(:translation_suffix_type) ? base_id.translation_suffix_type : nil
result += if ts_type == "version"
" (#{tl} version)"
elsif ts_type == "Translation"
" (#{tl} Translation)"
else
" (#{tl})"
end
else
tu = base_attrs.key?(:translation_upper) ? base_id.translation_upper : nil
if tu
ts_type = base_attrs.key?(:translation_suffix_type) ? base_id.translation_suffix_type : nil
result += if ts_type == "Translation"
" (#{tu} Translation)"
else
" (#{tu})"
end
end
end
ry = base_attrs.key?(:reaffirmation_year) ? base_id.reaffirmation_year : nil
result += " (R#{ry})" if ry
end
result
end
|
#to_urn ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/pubid/bsi/identifiers/consolidated_identifier.rb', line 96
def to_urn
base = identifiers&.first
return nil unless base
urn = base.to_urn if base.class.method_defined?(:to_urn)
return urn unless urn
identifiers[1..].each do |id|
if id.is_a?(Amendment)
urn += ":amd:#{id.amendment_number}"
urn += ":#{id.amendment_year}" if id.amendment_year
elsif id.is_a?(Corrigendum)
urn += ":cor:#{id.corrigendum_number}"
urn += ":#{id.corrigendum_year}" if id.corrigendum_year
end
end
urn
end
|
#type ⇒ Object
145
146
147
148
|
# File 'lib/pubid/bsi/identifiers/consolidated_identifier.rb', line 145
def type
base = identifiers&.first
base.type if base&.class&.attributes&.key?(:type)
end
|
#year ⇒ Object
125
126
127
128
|
# File 'lib/pubid/bsi/identifiers/consolidated_identifier.rb', line 125
def year
base = identifiers&.first
base.year if base&.class&.attributes&.key?(:year)
end
|