Class: RelatonIsoBib::IsoBibliographicItem
- Inherits:
-
RelatonBib::BibliographicItem
- Object
- RelatonBib::BibliographicItem
- RelatonIsoBib::IsoBibliographicItem
- Defined in:
- lib/relaton_iso_bib/iso_bibliographic_item.rb
Overview
Bibliographic item.
Constant Summary collapse
- TYPES =
%w[ standard international-standard technical-specification technical-report publicly-available-specification international-workshop-agreement guide ].freeze
Instance Attribute Summary collapse
- #doctype ⇒ String, NilClass readonly
- #editorialgroup ⇒ RelatonIsoBib::EditorialGroup readonly
- #ics ⇒ Array<RelatonIsoBib::Ics> readonly
- #structuredidentifier ⇒ RelatonIsoBib::StructuredIdentifier readonly
- #title(lang: nil) ⇒ Array<RelatonIsoBib::TypedTitleString> readonly
Instance Method Summary collapse
-
#disable_id_attribute ⇒ Object
rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity rubocop:enable Metrics/MethodLength, Metrics/PerceivedComplexity.
-
#initialize(**args) ⇒ IsoBibliographicItem
constructor
A new instance of IsoBibliographicItem.
-
#to_all_parts ⇒ Object
remove title part components and abstract.
- #to_hash ⇒ Hash
-
#to_most_recent_reference ⇒ Object
convert ISO:yyyy reference to reference to most recent instance of reference, removing date-specific infomration: date of publication, abstracts.
- #to_xml(builder = nil, **opts, &block) ⇒ String
- #url(type = :src) ⇒ String
Constructor Details
#initialize(**args) ⇒ IsoBibliographicItem
Returns a new instance of IsoBibliographicItem.
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 126 def initialize(**args) check_type args[:type] # check_language args.fetch(:language, []) # check_script args.fetch(:script, []) super_args = args.select do |k| i[id docnumber language script docstatus date abstract contributor edition version relation biblionote series medium place copyright link fetched docid formattedref extent accesslocation classification validity].include? k end.merge(type: "standard") super(super_args) @title = args.fetch(:title, []).reduce([]) do |a, t| if t.is_a? Hash a + typed_titles(t) else a << t end end if args[:editorialgroup] @editorialgroup = if args[:editorialgroup].is_a?(Hash) EditorialGroup.new(args[:editorialgroup]) else args[:editorialgroup] end end @structuredidentifier = args[:structuredidentifier] @doctype ||= args[:type] @ics = args.fetch(:ics, []).map { |i| i.is_a?(Hash) ? Ics.new(i) : i } # @link = args.fetch(:link, []).map do |s| # s.is_a?(Hash) ? RelatonBib::TypedUri.new(s) : s # end @id_attribute = true end |
Instance Attribute Details
#doctype ⇒ String, NilClass (readonly)
39 40 41 |
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 39 def doctype @doctype end |
#editorialgroup ⇒ RelatonIsoBib::EditorialGroup (readonly)
42 43 44 |
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 42 def editorialgroup @editorialgroup end |
#ics ⇒ Array<RelatonIsoBib::Ics> (readonly)
45 46 47 |
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 45 def ics @ics end |
#structuredidentifier ⇒ RelatonIsoBib::StructuredIdentifier (readonly)
33 34 35 |
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 33 def structuredidentifier @structuredidentifier end |
#title(lang: nil) ⇒ Array<RelatonIsoBib::TypedTitleString> (readonly)
|
|
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 35
|
Instance Method Details
#disable_id_attribute ⇒ Object
rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity rubocop:enable Metrics/MethodLength, Metrics/PerceivedComplexity
165 166 167 |
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 165 def disable_id_attribute @id_attribute = false end |
#to_all_parts ⇒ Object
remove title part components and abstract
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 170 def to_all_parts me = DeepClone.clone(self) me.disable_id_attribute @relation << RelatonBib::DocumentRelation.new( type: "partOf", bibitem: me, ) @language.each do |l| @title.delete_if { |t| t.type == "title-part" } ttl = @title.select { |t| t.type != "main" && t.title.language.include?(l) } tm_en = ttl.map { |t| t.title.content }.join " - " @title.detect { |t| t.type == "main" && t.title.language.include?(l) }&.title&.content = tm_en end @abstract = [] @docidentifier.each(&:remove_part) @docidentifier.each(&:all_parts) @structuredidentifier.remove_part @structuredidentifier.all_parts @all_parts = true end |
#to_hash ⇒ Hash
249 250 251 252 253 254 255 256 |
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 249 def to_hash hash = super hash["editorialgroup"] = editorialgroup.to_hash if editorialgroup hash["ics"] = single_element_array(ics) if ics&.any? hash["structuredidentifier"] = structuredidentifier.to_hash if structuredidentifier hash["type"] = doctype if doctype hash end |
#to_most_recent_reference ⇒ Object
convert ISO:yyyy reference to reference to most recent instance of reference, removing date-specific infomration: date of publication, abstracts. Make dated reference Instance relation of the redacated document
194 195 196 197 198 199 200 201 202 203 |
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 194 def to_most_recent_reference me = DeepClone.clone(self) me.disable_id_attribute @relation << RelatonBib::DocumentRelation.new(type: "instance", bibitem: me) @abstract = [] @date = [] @docidentifier.each &:remove_date @structuredidentifier&.remove_date @id&.sub! /-[12]\d\d\d/, "" end |
#to_xml(builder = nil, **opts, &block) ⇒ String
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 222 def to_xml(builder = nil, **opts, &block) if opts[:note]&.any? opts.fetch(:note, []).each do |n| @biblionote << RelatonBib::BiblioNote.new( content: n[:text], type: n[:type], format: "text/plain", ) end end super builder, **opts do |b| if opts[:bibdata] b.ext do b.doctype doctype if doctype # GB renders gbcommittee elements istead of an editorialgroup element. if respond_to? :committee committee&.to_xml b else editorialgroup&.to_xml b end ics.each { |i| i.to_xml b } structuredidentifier&.to_xml b yield b if block_given? end end end end |
#url(type = :src) ⇒ String
217 218 219 |
# File 'lib/relaton_iso_bib/iso_bibliographic_item.rb', line 217 def url(type = :src) @link.detect { |s| s.type == type.to_s }.content.to_s end |