relaton-bib 0.1.5 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cf4e678a0c2415cdcc4e408a4247bf6cf8437524
4
- data.tar.gz: 3e1042828c36498972abde6f0c43bfbd28d19f77
3
+ metadata.gz: 74853979be6433fe1cfa7326ef1cdc2a4894b0b7
4
+ data.tar.gz: 448612aa38f9c3f4ab9bfe4e345bb8f12a9d09fc
5
5
  SHA512:
6
- metadata.gz: 81d865c1e88a8b0996406586fc663148573aba25f24eb0ecbdbfbc98df1f47a7b93cfba477963e259f700170f70b3294a2a9ca9c0f8a193ba6a561e546b693ea
7
- data.tar.gz: f8119c6d775bf3247a8d028ca2e26ae2e466b484f5ec53232834ff122d5b91c1a81f3ca90b47d471c862f85d3364b5d4ca54d0d939d8c9de77d674fd90295578
6
+ metadata.gz: 7f37e2b4de8e9ba2585f56e02368d88f1fd7516d040f4495b221e3d39c9a5d001e3a2b79bbe6f228a58bcdf3f59b8114f1a55191cb3e6fc35cafa68d97b972d4
7
+ data.tar.gz: 7b65f1eec49d175efea99f893ca72827550e707246352bbb62eefd54b8da5346de4ea06b9732b6fdd4bbc977ea5a5a0fa71e4241e80f4393160320f4495e7a85
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- relaton-bib (0.1.5)
4
+ relaton-bib (0.1.6)
5
5
  addressable
6
6
  nokogiri (~> 1.8.4)
7
7
 
@@ -6,7 +6,7 @@ module RelatonBib
6
6
  # Bibliographic date.
7
7
  class BibliographicDate
8
8
  TYPES = %w[published accessed created implemented obsoleted confirmed
9
- updated issued].freeze
9
+ updated issued transmitted copied unchanged circulated].freeze
10
10
 
11
11
  # @return [String]
12
12
  attr_reader :type
@@ -24,7 +24,7 @@ module RelatonBib
24
24
  # @param from [String]
25
25
  # @param to [String]
26
26
  def initialize(type:, on: nil, from: nil, to: nil)
27
- raise ArgumentError, "expected :on or :form argument" unless on || from
27
+ raise ArgumentError, "expected :on or :from argument" unless on || from
28
28
 
29
29
  raise ArgumentError, %{Type "#{type}" is ivalid.} unless TYPES.include?(type)
30
30
 
@@ -19,6 +19,7 @@ require "relaton_bib/document_relation"
19
19
  require "relaton_bib/bib_item_locality"
20
20
  require "relaton_bib/xml_parser"
21
21
  require "relaton_bib/biblio_note"
22
+ require "relaton_bib/workers_pool"
22
23
 
23
24
 
24
25
  module RelatonBib
@@ -97,7 +98,7 @@ module RelatonBib
97
98
  # @!attribute [r] abstract
98
99
  # @return [Array<RelatonBib::FormattedString>]
99
100
 
100
- # @return [RelatonBib::DocumentStatus]
101
+ # @return [RelatonBib::DocumentStatus, NilClass]
101
102
  attr_reader :status
102
103
 
103
104
  # @return [RelatonBib::CopyrightAssociation]
@@ -175,7 +176,7 @@ module RelatonBib
175
176
  #
176
177
  # @param relations [Array<Hash>]
177
178
  # @option relations [String] :type
178
- # @option relations [RelatonBib::BibliographicItem] :bibitem
179
+ # @option relations [RelatonBib::BibliographicItem, RelatonIso::IsoBibliographicItem] :bibitem
179
180
  # @option relations [Array<RelatonBib::BibItemLocality>] :bib_locality
180
181
  def initialize(**args)
181
182
  if args[:type] && !TYPES.include?(args[:type])
@@ -209,10 +210,10 @@ module RelatonBib
209
210
  end
210
211
  end
211
212
 
212
- @id = args[:id] || args[:docid]&.first&.id&.strip&.gsub(/\s/, "")
213
+ @docidentifier = args[:docid] || []
214
+ @id = args[:id] || makeid(nil, false)
213
215
  @formattedref = args[:formattedref] if title.empty?
214
216
  @type = args[:type]
215
- @docidentifier = args[:docid] || []
216
217
  @docnumber = args[:docnumber]
217
218
  @edition = args[:edition]
218
219
  @version = args[:version]
@@ -248,10 +249,12 @@ module RelatonBib
248
249
  return nil if attribute && !@id_attribute
249
250
 
250
251
  id ||= @docidentifier.reject { |i| i.type == "DOI" }[0]
252
+ return unless id
253
+
251
254
  # contribs = publishers.map { |p| p&.entity&.abbreviation }.join '/'
252
255
  # idstr = "#{contribs}#{delim}#{id.project_number}"
253
256
  # idstr = id.project_number.to_s
254
- idstr = id.id.gsub(/:/, "-")
257
+ idstr = id.id.gsub(/:/, "-").gsub /\s/, ""
255
258
  # if id.part_number&.size&.positive? then idstr += "-#{id.part_number}"
256
259
  idstr.strip
257
260
  end
@@ -14,6 +14,27 @@ module RelatonBib
14
14
  @type = type
15
15
  end
16
16
 
17
+ # in docid manipulations, assume ISO as the default: id-part:year
18
+ def remove_part
19
+ case @type
20
+ when "Chinese Standard" then @id.sub!(/\.\d+/, "")
21
+ else
22
+ @id.sub!(/-\d+/, "")
23
+ end
24
+ end
25
+
26
+ def remove_date
27
+ case @type
28
+ when "Chinese Standard" then @id.sub!(/-[12]\d\d\d/, "")
29
+ else
30
+ @id.sub!(/:[12]\d\d\d/, "")
31
+ end
32
+ end
33
+
34
+ def all_parts
35
+ @id += " (all parts)"
36
+ end
37
+
17
38
  #
18
39
  # Add docidentifier xml element
19
40
  #
@@ -23,4 +44,4 @@ module RelatonBib
23
44
  builder.docidentifier(id, type: type)
24
45
  end
25
46
  end
26
- end
47
+ end
@@ -39,6 +39,7 @@ module RelatonBib
39
39
  # @param builder [Nokogiri::XML::Builder]
40
40
  def to_xml(builder, **opts)
41
41
  opts.delete :bibdata
42
+ opts.delete :note
42
43
  builder.relation(type: type) do
43
44
  bibitem.to_xml(builder, **opts)
44
45
  bib_locality.each do |l|
@@ -8,6 +8,8 @@ module RelatonBib
8
8
  # @return [RelatonBib::FormattedString]
9
9
  attr_reader :title
10
10
 
11
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
12
+
11
13
  # @param type [String]
12
14
  # @param title [RelatonBib::FormattedString, Hash]
13
15
  # @param content [String]
@@ -24,13 +26,14 @@ module RelatonBib
24
26
 
25
27
  @type = args[:type]
26
28
 
27
- # if args[:title]
28
- # @title = args[:title]
29
- # else
30
- fsargs = args.select { |k, _v| %i[content language script format].include? k }
31
- @title = args.fetch :title, FormattedString.new(fsargs)
32
- # end
29
+ if args[:title]
30
+ @title = args[:title]
31
+ else
32
+ fsargs = args.select { |k, _v| %i[content language script format].include? k }
33
+ @title = FormattedString.new(fsargs)
34
+ end
33
35
  end
36
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
34
37
 
35
38
  # @param builder [Nokogiri::XML::Builder]
36
39
  def to_xml(builder)
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "0.1.5".freeze
2
+ VERSION = "0.1.6".freeze
3
3
  end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RelatonBib
4
+ # Workers poll.
5
+ class WorkersPool
6
+ attr_accessor :nb_hits
7
+
8
+ def initialize(num_workers = 2)
9
+ @num_workers = num_workers < 2 ? 2 : num_workers
10
+ @queue = SizedQueue.new(num_workers * 2)
11
+ @result = []
12
+ @nb_hits = 0
13
+ end
14
+
15
+ def worker(&block)
16
+ @threads = Array.new @num_workers do
17
+ Thread.new do
18
+ until (item = @queue.pop) == :END
19
+ @result << yield(item) if block
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ def result
26
+ @threads.each(&:join)
27
+ @result
28
+ end
29
+
30
+ def <<(item)
31
+ @queue << item
32
+ self
33
+ end
34
+
35
+ def end
36
+ @num_workers.times { @queue << :END }
37
+ end
38
+
39
+ def size
40
+ @result.size
41
+ end
42
+ end
43
+ end
@@ -11,10 +11,13 @@ module RelatonBib
11
11
 
12
12
  private
13
13
 
14
+ # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
15
+
16
+ # @return [Hash]
14
17
  def item_data(bibitem)
15
18
  {
16
- id: bibitem[:id],
17
- type: bibitem[:type],
19
+ id: bibitem[:id]&.empty? ? nil : bibitem[:id],
20
+ type: bibitem[:type]&.empty? ? nil : bibitem[:type],
18
21
  fetched: bibitem.at("./fetched")&.text,
19
22
  titles: fetch_titles(bibitem),
20
23
  formattedref: fref(bibitem),
@@ -41,6 +44,7 @@ module RelatonBib
41
44
  validity: fetch_validity(bibitem),
42
45
  }
43
46
  end
47
+ # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
44
48
 
45
49
  def fetch_version(item)
46
50
  version = item.at "./version"
@@ -63,18 +67,23 @@ module RelatonBib
63
67
  end
64
68
  end
65
69
 
70
+ # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
71
+
66
72
  def fetch_series(item)
67
73
  item.xpath("./series").map do |sr|
68
74
  abbr = sr.at "abbreviation"
69
75
  abbreviation = abbr ? LocalizedString.new(abbr.text, abbr[:language], abbr[:script]) : nil
70
- Series.new(type: sr[:type], formattedref: fref(sr),
71
- title: ttitle(sr.at "title"), place: sr.at("place")&.text,
72
- organization: sr.at("organization")&.text, abbreviation: abbreviation,
73
- from: sr.at("from")&.text, to: sr.at("to")&.text, number: sr.at("number")&.text,
76
+ Series.new(
77
+ type: sr[:type], formattedref: fref(sr),
78
+ title: ttitle(sr.at("title")), place: sr.at("place")&.text,
79
+ organization: sr.at("organization")&.text,
80
+ abbreviation: abbreviation, from: sr.at("from")&.text,
81
+ to: sr.at("to")&.text, number: sr.at("number")&.text,
74
82
  partnumber: sr.at("partnumber")&.text
75
83
  )
76
84
  end
77
85
  end
86
+ # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
78
87
 
79
88
  def fetch_medium(item)
80
89
  medium = item.at("./medium")
@@ -111,23 +120,12 @@ module RelatonBib
111
120
  Validity.new begins: begins, ends: ends, revision: revision
112
121
  end
113
122
 
114
- # def get_id(did)
115
- # did.text.match(/^(?<project>.*?\d+)(?<hyphen>-)?(?(<hyphen>)(?<part>\d*))/)
116
- # end
117
-
123
+ # @param item [Nokogiri::XML::Element]
124
+ # @return [Array<RelatonBib::DocumentIdentifier>]
118
125
  def fetch_docid(item)
119
- ret = []
120
- item.xpath("./docidentifier").each do |did|
121
- #did = doc.at('/bibitem/docidentifier')
122
- # type = did.at("./@type")
123
- # if did.text == "IEV" then
124
- # ret << DocumentIdentifier.new(id: "IEV", nil)
125
- # else
126
- # id = get_id did
127
- ret << DocumentIdentifier.new(id: did.text, type: did[:type])
128
- # end
126
+ item.xpath("./docidentifier").map do |did|
127
+ DocumentIdentifier.new(id: did.text, type: did[:type])
129
128
  end
130
- ret
131
129
  end
132
130
 
133
131
  def fetch_titles(item)
@@ -155,10 +153,10 @@ module RelatonBib
155
153
  end
156
154
 
157
155
  def fetch_dates(item)
158
- item.xpath('./date').map do |d|
156
+ item.xpath("./date").map do |d|
159
157
  RelatonBib::BibliographicDate.new(
160
- type: d[:type], on: d.at('on')&.text, from: d.at('from')&.text,
161
- to: d.at('to')&.text
158
+ type: d[:type], on: d.at("on")&.text, from: d.at("from")&.text,
159
+ to: d.at("to")&.text
162
160
  )
163
161
  end
164
162
  end
@@ -253,7 +251,7 @@ module RelatonBib
253
251
  def fetch_copyright(item)
254
252
  cp = item.at("./copyright") || return
255
253
  org = cp&.at("owner/organization")
256
- name = org&.at("name").text
254
+ name = org&.at("name")&.text
257
255
  abbr = org&.at("abbreviation")&.text
258
256
  url = org&.at("uri")&.text
259
257
  entity = Organization.new(name: name, abbreviation: abbr, url: url)
@@ -280,7 +278,7 @@ module RelatonBib
280
278
  )
281
279
  end
282
280
  DocumentRelation.new(
283
- type: rel[:type],
281
+ type: rel[:type]&.empty? ? nil : rel[:type],
284
282
  bibitem: BibliographicItem.new(item_data(rel.at("./bibitem"))),
285
283
  bib_locality: localities,
286
284
  )
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-bib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-17 00:00:00.000000000 Z
11
+ date: 2019-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -178,6 +178,7 @@ files:
178
178
  - lib/relaton_bib/typed_uri.rb
179
179
  - lib/relaton_bib/validity.rb
180
180
  - lib/relaton_bib/version.rb
181
+ - lib/relaton_bib/workers_pool.rb
181
182
  - lib/relaton_bib/xml_parser.rb
182
183
  - relaton-bib.gemspec
183
184
  homepage: https://github.com/metanorma/relaton-item