relaton 3.1.5 → 3.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1ea5d8ada503e918f9bca0be141bc0ae76b7bdf89c634c2588b6609eb06251bf
4
- data.tar.gz: 2b5578cd9fbb7907b1c9c4be0b3e066fbac0fa8884e59264a365cc55e5737f40
3
+ metadata.gz: f9a1dcc62dca48c6e2c80ad43a9e404d13ac3692be82282545271322681ca3d7
4
+ data.tar.gz: 3997131f34e955e52439d88b8c943a63984ca3df5f77a5a379eff5a8b7cf7afb
5
5
  SHA512:
6
- metadata.gz: a64557918b5ae5ab276bc3849f4c73bb20e31a3ddc618a7db33cce060c40a2f8780303181f2c6dfa94d0309d0e75146337690be7eb296ce469b298ecf6cd0641
7
- data.tar.gz: 44d22a95a792c4396b37c223ad44077bd87562a4c8e5f26889504e86078a229357baacbe1bbc4217dbe4bfed55614dca7e64aaeee96c7c8804336cd517a06956
6
+ metadata.gz: 99c5dbe4bfa6197a209df83a9fc07bf9516f9915aa98158adf64da1168b65d2f8811f7e9e87db9cccf17880aa0e8910c94e49cb1d53d532143d8324b1620936a
7
+ data.tar.gz: 6fc0ef51ff656c6776efa46f33306789569bfa72743caebf594b3ff2ec441fc0b3838521d6edd6bb37c40b83c7ff28158a49fa4a6cad18e6add449a4bec4b831
data/README.adoc CHANGED
@@ -508,6 +508,7 @@ usage and architecture notes.
508
508
  Standards bodies:
509
509
 
510
510
  link:lib/relaton/3gpp/README.adoc[3gpp],
511
+ link:lib/relaton/arxiv/README.adoc[arxiv],
511
512
  link:lib/relaton/bipm/README.adoc[bipm],
512
513
  link:lib/relaton/bsi/README.adoc[bsi],
513
514
  link:lib/relaton/calconnect/README.adoc[calconnect],
@@ -0,0 +1,59 @@
1
+ = Relaton::Arxiv: retrieves arXiv e-prints from the arXiv API
2
+
3
+ `Relaton::Arxiv` fetches the metadata of an https://arxiv.org[arXiv] e-print
4
+ from the https://info.arxiv.org/help/api/[arXiv API] and answers a
5
+ `Relaton::Bib::ItemData`.
6
+
7
+ == Usage
8
+
9
+ `Relaton::Arxiv::Bibliography.get` takes an arXiv id, with or without the
10
+ `arXiv:` prefix (any case) and with or without a version. An id with no
11
+ version answers the latest version.
12
+
13
+ [source,ruby]
14
+ ----
15
+ require "relaton/arxiv"
16
+
17
+ item = Relaton::Arxiv::Bibliography.get "arXiv:1706.03762"
18
+ [relaton-arxiv] INFO: (arXiv:1706.03762) Fetching from arXiv ...
19
+ [relaton-arxiv] INFO: (arXiv:1706.03762) Found: `arXiv:1706.03762v7`
20
+
21
+ item.docidentifier.map(&:content)
22
+ => ["arXiv:1706.03762v7", "10.48550/arXiv.1706.03762"]
23
+
24
+ # an old-style id, a version
25
+ Relaton::Arxiv::Bibliography.get "arxiv:hep-th/9901001v2"
26
+ ----
27
+
28
+ Through `Relaton::Db`:
29
+
30
+ [source,ruby]
31
+ ----
32
+ require "relaton"
33
+
34
+ Relaton::Db.new("cache", nil).fetch "arXiv:2301.00001"
35
+ ----
36
+
37
+ == Identifiers
38
+
39
+ Both arXiv id schemes are read (https://info.arxiv.org/help/arxiv_identifier_for_services.html):
40
+
41
+ * new: `YYMM.NNNN` (0704 to 1412), `YYMM.NNNNN` (from 1501), as `2301.00001v1`;
42
+ * old: `archive[.SC]/YYMMNNN`, as `hep-th/9901001`, `math.GT/0309136`.
43
+
44
+ == Data model
45
+
46
+ [cols="1,2"]
47
+ |===
48
+ | Atom element | `Bib::ItemData`
49
+
50
+ | `id` | primary docidentifier `arXiv` (versioned), `version`; and a docidentifier `DOI` `10.48550/arXiv.<id>`
51
+ | `title` | `title` (`main`)
52
+ | `summary` | `abstract`
53
+ | `published`, `updated` | `date`
54
+ | `author` (`name`, `arxiv:affiliation`) | contributor, role `author`
55
+ | `arxiv:primary_category`, `category` | `keyword` (the primary first)
56
+ | `link` (`alternate`, `pdf`) | `source` (`src`, `pdf`)
57
+ | `arxiv:journal_ref` | `note` (`journal-ref`); the type is then `article`, else `misc`
58
+ | `arxiv:doi` | relation `hasManifestation` to the journal article
59
+ |===
@@ -0,0 +1,42 @@
1
+ module Relaton
2
+ module Arxiv
3
+ #
4
+ # The arXiv API (https://info.arxiv.org/help/api/). One `id_list` query
5
+ # answers one Atom feed; an unversioned id answers the latest version.
6
+ #
7
+ module Api
8
+ extend self
9
+
10
+ ENDPOINT = "https://export.arxiv.org/api/query".freeze
11
+
12
+ # Transport failures, raised as `Relaton::RequestError` so that
13
+ # `Db#net_retry` retries them (as `Relaton::Doi::Http` does).
14
+ NETWORK_ERRORS = [
15
+ SocketError, SystemCallError, Timeout::Error, OpenSSL::SSL::SSLError,
16
+ EOFError, IOError, Net::ProtocolError
17
+ ].freeze
18
+
19
+ #
20
+ # The Atom feed for an arXiv id. A feed with no entry is how arXiv
21
+ # answers an id it does not have, so only a transport failure raises.
22
+ #
23
+ # @param id [String] the bare id, `2301.00001v1` or `hep-th/9901001`
24
+ # @return [String] the Atom XML
25
+ # @raise [Relaton::RequestError] a non-200 answer or a network failure
26
+ #
27
+ def feed(id)
28
+ uri = URI ENDPOINT
29
+ uri.query = URI.encode_www_form(id_list: id)
30
+ response = Net::HTTP.get_response uri
31
+ unless response.is_a? Net::HTTPSuccess
32
+ raise Relaton::RequestError,
33
+ "arXiv API answered #{response.code} for #{id}"
34
+ end
35
+
36
+ response.body.dup.force_encoding Encoding::UTF_8
37
+ rescue *NETWORK_ERRORS => e
38
+ raise Relaton::RequestError, "arXiv API: #{e.class}: #{e.message}"
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,45 @@
1
+ module Relaton
2
+ module Arxiv
3
+ #
4
+ # Fetch an arXiv e-print by its id.
5
+ #
6
+ module Bibliography
7
+ extend self
8
+
9
+ #
10
+ # @param ref [String, Pubid::Arxiv::Identifier] `arXiv:2301.00001v1`,
11
+ # `arxiv:hep-th/9901001`; a parsed pubid is not mutated
12
+ # @param _year [String, nil] ignored: the id carries its year
13
+ # @param _opts [Hash]
14
+ # @return [Relaton::Bib::ItemData, nil]
15
+ # @raise [Relaton::RequestError] the arXiv API did not answer
16
+ #
17
+ def get(ref, _year = nil, _opts = {})
18
+ pubid = ref.is_a?(::Pubid::Arxiv::Identifier) ? ref : parse(ref)
19
+ unless pubid
20
+ Util.info "Not an arXiv identifier.", key: ref.to_s
21
+ return
22
+ end
23
+
24
+ Util.info "Fetching from arXiv ...", key: pubid.to_s
25
+ item = Parser.parse Api.feed(pubid.to_s(with_publisher: false))
26
+ if item
27
+ Util.info "Found: `#{item.docidentifier.first.content}`", key: pubid.to_s
28
+ else
29
+ Util.info "Not found.", key: pubid.to_s
30
+ end
31
+ item
32
+ end
33
+
34
+ #
35
+ # @param ref [String]
36
+ # @return [Pubid::Arxiv::Identifier, nil]
37
+ #
38
+ def parse(ref)
39
+ ::Pubid::Arxiv.parse ref.strip
40
+ rescue ArgumentError, ::Pubid::Errors::Error
41
+ nil
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,167 @@
1
+ module Relaton
2
+ module Arxiv
3
+ #
4
+ # Map the entry of an arXiv API Atom feed to a `Bib::ItemData`. Elements
5
+ # are found by local name: Atom elements have the default namespace, and
6
+ # the arXiv extensions (`arxiv:doi`, `arxiv:journal_ref`, …) their own.
7
+ #
8
+ class Parser
9
+ ATTRS = %i[type fetched title docidentifier source date contributor
10
+ abstract version keyword note relation ext].freeze
11
+
12
+ # The DOI prefix under which arXiv registers each e-print with DataCite.
13
+ DOI_PREFIX = "10.48550/arXiv.".freeze
14
+
15
+ ID_PATTERN = %r{\Ahttps?://arxiv\.org/abs/(?<id>.+?)(?:v(?<version>\d+))?\z}
16
+
17
+ #
18
+ # @param xml [String] the Atom feed
19
+ # @return [Relaton::Bib::ItemData, nil] nil when the feed has no entry,
20
+ # or only arXiv's error entry (`<id>https://arxiv.org/api/errors#…`),
21
+ # which is how arXiv answers an id it rejects
22
+ #
23
+ def self.parse(xml)
24
+ doc = Moxml.new.parse xml
25
+ entry = doc.xpath("//*[local-name()='entry']").first
26
+ return unless entry
27
+
28
+ id = entry.children.detect { |n| n.is_a?(Moxml::Element) && n.name == "id" }
29
+ match = id && ID_PATTERN.match(id.text.strip)
30
+ new(entry, match).parse if match
31
+ end
32
+
33
+ # @param entry [Moxml::Element]
34
+ # @param id [MatchData] the entry id matched by ID_PATTERN
35
+ def initialize(entry, id)
36
+ @entry = entry
37
+ @id = id
38
+ end
39
+
40
+ # @return [Relaton::Bib::ItemData]
41
+ def parse
42
+ Bib::ItemData.new(**ATTRS.to_h { |a| [a, send("parse_#{a}")] })
43
+ end
44
+
45
+ private
46
+
47
+ def children(name)
48
+ @entry.children.select { |n| n.is_a?(Moxml::Element) && n.name == name }
49
+ end
50
+
51
+ def text(name, node = @entry)
52
+ el = node.children.detect { |n| n.is_a?(Moxml::Element) && n.name == name }
53
+ el && squeeze(el.text)
54
+ end
55
+
56
+ def squeeze(str)
57
+ str.to_s.gsub(/\s+/, " ").strip
58
+ end
59
+
60
+ def bare_id = @id[:id]
61
+
62
+ # An e-print a journal published is cited as an article; otherwise it
63
+ # is a preprint.
64
+ def parse_type
65
+ text("journal_ref") ? "article" : "misc"
66
+ end
67
+
68
+ def parse_fetched = Date.today.to_s
69
+
70
+ def parse_title
71
+ title = text("title")
72
+ title && !title.empty? ? [Bib::Title.new(type: "main", content: title)] : []
73
+ end
74
+
75
+ def parse_docidentifier
76
+ versioned = "arXiv:#{bare_id}#{"v#{@id[:version]}" if @id[:version]}"
77
+ [
78
+ Bib::Docidentifier.new(type: "arXiv", content: versioned, primary: true),
79
+ Bib::Docidentifier.new(type: "DOI", content: "#{DOI_PREFIX}#{bare_id}"),
80
+ ]
81
+ end
82
+
83
+ def parse_source
84
+ children("link").filter_map do |link|
85
+ case [link["rel"], link["title"]]
86
+ in ["alternate", _] then Bib::Uri.new(type: "src", content: link["href"])
87
+ in ["related", "pdf"] then Bib::Uri.new(type: "pdf", content: link["href"])
88
+ else nil
89
+ end
90
+ end
91
+ end
92
+
93
+ def parse_date
94
+ %w[published updated].filter_map do |type|
95
+ value = text(type)
96
+ Bib::Date.new(type: type, at: value[0, 10]) if value && !value.empty?
97
+ end
98
+ end
99
+
100
+ def parse_contributor
101
+ children("author").filter_map do |author|
102
+ name = text("name", author)
103
+ next if name.nil? || name.empty?
104
+
105
+ Bib::Contributor.new(
106
+ person: create_person(name, author),
107
+ role: [Bib::Contributor::Role.new(type: "author")],
108
+ )
109
+ end
110
+ end
111
+
112
+ def create_person(name, author)
113
+ affiliation = author.children.filter_map do |n|
114
+ next unless n.is_a?(Moxml::Element) && n.name == "affiliation"
115
+
116
+ org = Bib::Organization.new(
117
+ name: [Bib::TypedLocalizedString.new(content: squeeze(n.text))],
118
+ )
119
+ Bib::Affiliation.new(organization: org)
120
+ end
121
+ Bib::Person.new(
122
+ name: Bib::FullName.new(completename: Bib::LocalizedString.new(content: name)),
123
+ affiliation: affiliation,
124
+ )
125
+ end
126
+
127
+ def parse_abstract
128
+ summary = text("summary")
129
+ summary && !summary.empty? ? [Bib::Abstract.new(content: summary)] : []
130
+ end
131
+
132
+ def parse_version
133
+ @id[:version] ? [Bib::Version.new(content: @id[:version])] : []
134
+ end
135
+
136
+ # The categories, the primary first.
137
+ def parse_keyword
138
+ primary = children("primary_category").first&.[]("term")
139
+ terms = children("category").map { |c| c["term"] }
140
+ ([primary] + terms).compact.uniq.map do |term|
141
+ Bib::Keyword.new(vocab: Bib::LocalizedString.new(content: term))
142
+ end
143
+ end
144
+
145
+ def parse_note
146
+ ref = text("journal_ref")
147
+ ref ? [Bib::Note.new(type: "journal-ref", content: ref)] : []
148
+ end
149
+
150
+ # The journal article an e-print became, by the DOI arXiv records.
151
+ def parse_relation
152
+ doi = text("doi")
153
+ return [] unless doi && !doi.empty?
154
+
155
+ # An ItemData, not an ItemBase: the YAML serializer rejects an
156
+ # ItemBase in a relation (Lutaml::Model::IncorrectModelError).
157
+ docid = Bib::Docidentifier.new(type: "DOI", content: doi)
158
+ [Bib::Relation.new(type: "hasManifestation",
159
+ bibitem: Bib::ItemData.new(docidentifier: [docid]))]
160
+ end
161
+
162
+ def parse_ext
163
+ Bib::Ext.new(flavor: "arxiv")
164
+ end
165
+ end
166
+ end
167
+ end
@@ -0,0 +1,66 @@
1
+ require_relative "../core/processor"
2
+
3
+ module Relaton
4
+ module Arxiv
5
+ class Processor < Relaton::Core::Processor
6
+ attr_reader :idtype
7
+
8
+ def initialize # rubocop:disable Lint/MissingSuper
9
+ @short = :relaton_arxiv
10
+ @prefix = "arXiv"
11
+ @pubid_flavor = :Arxiv # prefixes and the Db cache key
12
+ @defaultprefix = /^arXiv[:\s]/i
13
+ @idtype = "arXiv"
14
+ @datasets = %w[]
15
+ end
16
+
17
+ # @param code [String, Pubid::Arxiv::Identifier]
18
+ # @param date [String, nil] year (ignored: the id carries it)
19
+ # @param opts [Hash]
20
+ # @return [Relaton::Bib::ItemData, nil]
21
+ def get(code, date, opts)
22
+ require_relative "../arxiv"
23
+ ::Relaton::Arxiv::Bibliography.get(code, date, opts)
24
+ end
25
+
26
+ # `Pubid.parse` routes by a case-sensitive prefix; `Pubid::Arxiv.parse`
27
+ # also reads `arxiv:…` and a bare id.
28
+ def cache_pubid(ref)
29
+ require "pubid"
30
+ ::Pubid::Arxiv.parse ref.strip
31
+ rescue ArgumentError, ::Pubid::Errors::Error
32
+ require_relative "../bib"
33
+ Relaton::Bib::Util.info "does not parse as an arXiv id; passing " \
34
+ "the reference to the flavor as written",
35
+ "relaton-db", key: ref
36
+ nil
37
+ end
38
+
39
+ # An arXiv id carries its year and month, and they are identity: a
40
+ # year option must not make a key for another month's paper.
41
+ def fold_year(pubid, _year)
42
+ pubid
43
+ end
44
+
45
+ # @param xml [String]
46
+ # @return [Relaton::Bib::ItemData]
47
+ def from_xml(xml)
48
+ require_relative "../arxiv"
49
+ ::Relaton::Bib::Bibitem.from_xml xml
50
+ end
51
+
52
+ # @param hash [Hash]
53
+ # @return [Relaton::Bib::ItemData]
54
+ def from_yaml(hash)
55
+ require_relative "../arxiv"
56
+ ::Relaton::Bib::Bibitem.from_hash hash
57
+ end
58
+
59
+ # @return [String]
60
+ def grammar_hash
61
+ require_relative "../arxiv"
62
+ @grammar_hash ||= ::Relaton::Arxiv.grammar_hash
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,8 @@
1
+ module Relaton
2
+ module Arxiv
3
+ module Util
4
+ extend Relaton::Bib::Util
5
+ PROGNAME = "relaton-arxiv".freeze
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,23 @@
1
+ require "net/http"
2
+ require "digest/md5"
3
+ require "pubid"
4
+ require "moxml"
5
+ require_relative "bib"
6
+ require_relative "version"
7
+ require_relative "core/request_error"
8
+ require_relative "arxiv/util"
9
+ require_relative "arxiv/parser"
10
+ require_relative "arxiv/api"
11
+ require_relative "arxiv/bibliography"
12
+
13
+ module Relaton
14
+ # arXiv e-prints, from the arXiv API (relaton#42).
15
+ module Arxiv
16
+ module_function
17
+
18
+ # @return [String]
19
+ def grammar_hash
20
+ Digest::MD5.hexdigest Relaton::VERSION
21
+ end
22
+ end
23
+ end
@@ -1,20 +1,45 @@
1
- require_relative "element_finder"
2
-
3
1
  module Relaton
2
+ # A Relaton collection: a title, an author, a doctype and a list of items,
3
+ # where an item is a bibliographic item (`Relaton::Bibdata`) or a nested
4
+ # collection.
5
+ #
6
+ # The XML is read and written by the lutaml-model mapper
7
+ # `Relaton::CollectionXml` (relaton#459), as `Relaton::Bib::Item` maps
8
+ # `Relaton::Bib::ItemData`. The YAML (`#to_h`, `{"root" => …}`) is the
9
+ # format `Relaton::Cli::CollectionStore` keeps on disk, unchanged.
4
10
  class Bibcollection
5
- extend Relaton::ElementFinder
6
-
7
11
  ATTRIBS = %i[title items doctype author].freeze
8
12
 
9
- attr_accessor(*ATTRIBS)
13
+ attr_accessor :title, :doctype, :author
10
14
 
11
- # @param options [Hash]
12
- def initialize(options)
15
+ # Options of `#to_xml` that `CollectionXml` hands to the items.
16
+ attr_accessor :item_options
17
+
18
+ # @param options [Hash] the collection's attributes, with String or
19
+ # Symbol keys; an item is a Hash, a bibliographic item, a
20
+ # `Relaton::Bibdata` or a `Relaton::Bibcollection`
21
+ def initialize(options = {})
22
+ options ||= {}
13
23
  ATTRIBS.each do |k|
14
- value = options[k] || options[k.to_s]
15
- send("#{k}=", value)
24
+ send "#{k}=", options.key?(k) ? options[k] : options[k.to_s]
16
25
  end
17
- reduce_items
26
+ end
27
+
28
+ # @param source [String, #to_xml] Relaton collection XML, or a parsed
29
+ # document that answers `to_xml`
30
+ # @return [Relaton::Bibcollection]
31
+ def self.from_xml(source)
32
+ source = source.to_xml unless source.is_a?(String)
33
+ CollectionXml.from_xml source
34
+ end
35
+
36
+ def items
37
+ @items ||= []
38
+ end
39
+
40
+ # @param value [Array<Hash, Relaton::Bibdata, Relaton::Bibcollection>, nil]
41
+ def items=(value)
42
+ @items = (value || []).map { |item| new_bib_item_class item }
18
43
  end
19
44
 
20
45
  # arbitrary number, must sort after all bib items
@@ -28,59 +53,18 @@ module Relaton
28
53
  items << new_bib_item_class(item)
29
54
  end
30
55
 
31
- # rubocop:disable Metrics/MethodLength
32
-
33
- # @param source [Nokogiri::XML::Element]
34
- def self.from_xml(source)
35
- title = find_html("./relaton-collection/title", source)
36
- author = find_html(
37
- "./relaton-collection/contributor[role/@type='author']/organization/"\
38
- "name", source
39
- )
40
-
41
- items = find_xpath("./relaton-collection/relation", source)&.map do |item|
42
- bibdata = find("./bibdata|./bibitem", item)
43
- klass = bibdata ? Bibdata : Bibcollection
44
- klass.from_xml(bibdata || item)
45
- end
46
-
47
- new(title: title, author: author, items: items)
48
- end
49
-
50
- # rubocop:disable Metrics/AbcSize
51
-
52
- # @param opts [Hash]
56
+ # @param opts [Hash] options for the items' `to_xml`
53
57
  # @return [String] XML
54
58
  def to_xml(opts = {})
55
- items.sort_by! &:doc_number
56
-
57
- collection_type = if doctype
58
- "type=\"#{doctype}\""
59
- else
60
- 'xmlns="https://open.ribose.com/relaton-xml"'
61
- end
62
-
63
- ret = "<relaton-collection #{collection_type}>"
64
- ret += "<title>#{xml_escape(title)}</title>" if title
65
- if author
66
- ret += "<contributor><role type='author'/><organization><name>"\
67
- "#{xml_escape(author)}</name></organization></contributor>"
68
- end
69
- unless items.empty?
70
- items.each do |item|
71
- ret += "<relation type='partOf'>"
72
- ret += item.to_xml(opts)
73
- ret += "</relation>\n"
74
- end
75
- end
76
- ret += "</relaton-collection>\n"
59
+ items.sort_by!(&:doc_number)
60
+ self.item_options = opts.select { |k, _| k.is_a? Symbol }
61
+ CollectionXml.to_xml self
77
62
  end
78
- # rubocop:enable Metrics/AbcSize
79
63
 
80
64
  # @param item [Hash, RelatonBib::BibliographicItem, Relatin::Bibdata,
81
65
  # Relaton::Bibcollection]
82
66
  # @return [Relaton::Bibdata, Relaton::Bibcollection]
83
- def new_bib_item_class(item)
67
+ def new_bib_item_class(item) # rubocop:disable Metrics/MethodLength
84
68
  if item.is_a?(Hash)
85
69
  # `#to_h` writes a nested collection as `{"root" => …}`.
86
70
  if item["root"].is_a?(Hash)
@@ -96,10 +80,9 @@ module Relaton
96
80
  else ::Relaton::Bibdata.new(item)
97
81
  end
98
82
  end
99
- # rubocop:enable Metrics/MethodLength
100
83
 
101
84
  def items_flattened
102
- items.sort_by! &:doc_number
85
+ items.sort_by!(&:doc_number)
103
86
 
104
87
  items.reduce([]) do |acc, item|
105
88
  acc << if item.is_a? ::Relaton::Bibcollection
@@ -115,35 +98,14 @@ module Relaton
115
98
  end
116
99
 
117
100
  def to_h
118
- items.sort_by! &:doc_number
119
-
120
- a = ATTRIBS.reduce({}) do |acc, k|
121
- acc[k.to_s] = send(k)
122
- acc
123
- end
101
+ items.sort_by!(&:doc_number)
124
102
 
103
+ a = ATTRIBS.each_with_object({}) { |k, acc| acc[k.to_s] = send(k) }
125
104
  a["items"] = a["items"].map(&:to_h)
126
105
 
127
106
  { "root" => a }
128
107
  end
129
-
130
- private
131
-
132
- def reduce_items
133
- self.items = (items || []).reduce([]) do |acc, item|
134
- acc << if item.is_a?(Bibcollection) || item.is_a?(Bibdata)
135
- item
136
- else new_bib_item_class(item)
137
- end
138
- end
139
- end
140
-
141
- # Escape bare & in content for XML serialization, leaving already-encoded
142
- # entity references (&amp;, &#123;, &#x1f;) and inline markup (<em> etc.)
143
- # untouched. This prevents invalid XML when plain-text values (e.g. from
144
- # YAML) contain literal ampersands.
145
- def xml_escape(str)
146
- str.gsub(/&(?![a-zA-Z][a-zA-Z0-9]*;|#[0-9]+;|#x[0-9a-fA-F]+;)/, "&amp;")
147
- end
148
108
  end
149
109
  end
110
+
111
+ require_relative "collection_xml"