Class: Relaton::Bib::ItemData
Overview
This class represents the data of a bibliographic item.
It needed to keep data fot different types of representations (bibitem, bibdata ...).
@TODO: remove this class when Lutaml Model will support transformation between different types of models.
Direct Known Subclasses
Relaton::Bipm::ItemData, Calconnect::ItemData, Ccsds::ItemData, Cen::ItemData, Cie::ItemData, Ecma::ItemData, Etsi::ItemData, Gb::ItemData, Iana::ItemData, Iec::ItemData, Ieee::ItemData, Ietf::ItemData, Iho::ItemData, Iso::ItemData, Itu::ItemData, Jis::ItemData, Nist::ItemData, Oasis::ItemData, Ogc::ItemData, Oiml::ItemData, Omg::ItemData, Plateau::ItemData, ThreeGpp::ItemData, Un::ItemData, W3c::ItemData, Xsf::ItemData
Constant Summary
collapse
- ATTRIBUTES =
%i[
type schema_version fetched formattedref docnumber edition status
medium size validity ext
].freeze
- COLLECTION_ATTRBUTES =
%i[
date contributor version note language locale script
copyright series place price extent accesslocation license
classification keyword depiction
].freeze
- COLLECTION_WRITE_ONLY_ATTRIBUTES =
%i[title abstract source relation].freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
included
#array
Constructor Details
#initialize(**args) ⇒ ItemData
Returns a new instance of ItemData.
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/relaton/bib/item_data.rb', line 27
def initialize(**args)
ATTRIBUTES.each { |attr| instance_variable_set("@#{attr}", args[attr]) }
(COLLECTION_ATTRBUTES + COLLECTION_WRITE_ONLY_ATTRIBUTES).each do |attr|
instance_variable_set("@#{attr}", args[attr] || [])
end
@docidentifier = args[:docidentifier] || []
self.schema_version = schema
@id = args[:id]
create_id
end
|
Instance Attribute Details
#docidentifier ⇒ Object
Returns the value of attribute docidentifier.
25
26
27
|
# File 'lib/relaton/bib/item_data.rb', line 25
def docidentifier
@docidentifier
end
|
#id ⇒ Object
Returns the value of attribute id.
25
26
27
|
# File 'lib/relaton/bib/item_data.rb', line 25
def id
@id
end
|
Instance Method Details
#abstract(lang = nil) ⇒ Object
109
110
111
112
113
|
# File 'lib/relaton/bib/item_data.rb', line 109
def abstract(lang = nil)
return @abstract if lang.nil?
@abstract.select { |a| a.language == lang.to_s }
end
|
#create_id(without_date: false) ⇒ Object
93
94
95
96
97
98
99
100
101
|
# File 'lib/relaton/bib/item_data.rb', line 93
def create_id(without_date: false)
return id if id && !id.empty?
docid = find_primary_docid
return unless docid
pubid = without_date ? docid.content.sub(/:\d{4}$/, "") : docid.content
self.id = pubid.to_s.gsub(/\W+/, "")
end
|
#create_relation(**args) ⇒ Object
167
168
169
170
171
172
173
|
# File 'lib/relaton/bib/item_data.rb', line 167
def create_relation(**args)
if defined?(namespace::Relation)
namespace::Relation.new(**args)
else
Relation.new(**args)
end
end
|
#deep_clone ⇒ Object
163
164
165
|
# File 'lib/relaton/bib/item_data.rb', line 163
def deep_clone
namespace::Item.from_yaml namespace::Item.to_yaml(self)
end
|
#delete_title_part! ⇒ Object
175
176
177
|
# File 'lib/relaton/bib/item_data.rb', line 175
def delete_title_part!
title&.delete_if { |t| t.type == "title-part" }
end
|
#ext_remove_date ⇒ Object
197
198
199
200
201
|
# File 'lib/relaton/bib/item_data.rb', line 197
def ext_remove_date
return unless ext
array(ext.structuredidentifier).each(&:remove_date!)
end
|
#ext_to_all_parts! ⇒ Object
189
190
191
192
193
194
195
|
# File 'lib/relaton/bib/item_data.rb', line 189
def ext_to_all_parts!
return unless ext
array(ext.structuredidentifier).each(&:to_all_parts!)
end
|
#relation(type = nil) ⇒ Object
121
122
123
124
125
|
# File 'lib/relaton/bib/item_data.rb', line 121
def relation(type = nil)
return @relation if type.nil?
@relation&.select { |r| r.type == type.to_s }
end
|
#schema ⇒ String
54
55
56
|
# File 'lib/relaton/bib/item_data.rb', line 54
def schema
@schema ||= Relaton.schema_versions["relaton-models"]
end
|
#source(src = nil) ⇒ Object
115
116
117
118
119
|
# File 'lib/relaton/bib/item_data.rb', line 115
def source(src = nil)
return @source if src.nil?
@source.find { |s| s.type == src.to_s }&.content
end
|
#title(lang = nil) ⇒ Object
103
104
105
106
107
|
# File 'lib/relaton/bib/item_data.rb', line 103
def title(lang = nil)
return @title if lang.nil?
@title.select { |t| t.language == lang.to_s }
end
|
#title_update_main ⇒ Object
rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
179
180
181
182
183
184
185
186
187
|
# File 'lib/relaton/bib/item_data.rb', line 179
def title_update_main language&.each do |lang|
ttl = title.select { |t| t.type != "main" && t.language == lang }
next if ttl.empty?
tm_lang = ttl.map(&:content).join " - "
title.detect { |t| t.type == "main" && t.language == lang }&.content = tm_lang
end
end
|
#to_all_parts ⇒ Object
remove title part components and abstract
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/relaton/bib/item_data.rb', line 66
def to_all_parts me = deep_clone
me.relation ||= []
to_relation_item
me.relation << create_relation(type: "instanceOf", bibitem: self)
me.delete_title_part!
me.title_update_main
me.abstract = []
me.docidentifier.each(&:to_all_parts!)
me.ext_to_all_parts!
me
end
|
#to_h(**opts) ⇒ Object
145
146
147
148
149
|
# File 'lib/relaton/bib/item_data.rb', line 145
def to_h(**opts)
add_notes opts[:note] do
namespace::Item.to_hash(self)
end
end
|
#to_json(**opts) ⇒ Object
139
140
141
142
143
|
# File 'lib/relaton/bib/item_data.rb', line 139
def to_json(**opts)
add_notes opts[:note] do
namespace::Item.to_json(self)
end
end
|
#to_most_recent_reference ⇒ Object
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/relaton/bib/item_data.rb', line 80
def to_most_recent_reference
me = deep_clone
to_relation_item
me.relation ||= []
me.relation << create_relation(type: "instanceOf", bibitem: self)
me.abstract = []
me.date = []
me.docidentifier.each(&:remove_date!)
me.ext_remove_date
me.create_id without_date: true
me
end
|
#to_relation_item ⇒ Object
58
59
60
61
62
63
|
# File 'lib/relaton/bib/item_data.rb', line 58
def to_relation_item
self.id = nil
self.schema_version = nil
self.fetched = nil
ext&.schema_version = nil
end
|
#to_xml(bibdata: false, **opts) ⇒ Object
127
128
129
130
131
|
# File 'lib/relaton/bib/item_data.rb', line 127
def to_xml(bibdata: false, **opts)
add_notes opts[:note] do
bibdata ? namespace::Bibdata.to_xml(self) : namespace::Bibitem.to_xml(self)
end
end
|
#to_yaml(**opts) ⇒ Object
133
134
135
136
137
|
# File 'lib/relaton/bib/item_data.rb', line 133
def to_yaml(**opts)
add_notes opts[:note] do
namespace::Item.to_yaml(self)
end
end
|