relaton-bib 0.3.4 → 0.3.9

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: ee06437cee7f0efbacf8d04554136258ad4544f4
4
- data.tar.gz: 3608ad874a15aa0a7c1d2d03270dc02a2a308dfd
3
+ metadata.gz: c135f7e0e77b7cfa7c31ae9743e0c6bf716a27e0
4
+ data.tar.gz: 4998ac95553d5ab1e6248b48e7c41e36179c49c3
5
5
  SHA512:
6
- metadata.gz: 45f05d3a1362dcb45a09c7a04696eb87a48094eaba7314271a519c13c85e83ddbeb85e2c6ccbad8e3f7a064a70c471dc6270684efabce3f2e09374c151fd38ad
7
- data.tar.gz: 78315011778a04275ff534780f3138bb3f6e2c2476a6f7e7f1ea3287856664dffa80fe678ed0294494a5bed0d1d331c8c1f700d939ba4a7dad813fd435de3a53
6
+ metadata.gz: 290f43263f27e6a5f66e091d89bb95e296470311994525359dfd7f8dc63c11e329b404a6a56f8f834666e78f7a6aea6d7b5c05e3b4563f225454cad119ec7f33
7
+ data.tar.gz: 40f1bb2b469029b5cfa334207bd1d230deb49b4eae361dec3ef221f2efe3714e91e22c1d0706c8f6e43f14343907b9b6d08be6e75959b2c10d483234d182cf11
@@ -0,0 +1,27 @@
1
+ # Auto-generated !!! Do not edit it manually
2
+ # use ci-master https://github.com/metanorma/metanorma-build-scripts
3
+ name: macos
4
+
5
+ on: [push]
6
+
7
+ jobs:
8
+ test-macos:
9
+ name: Test on Ruby ${{ matrix.ruby }} macOS
10
+ runs-on: macos-latest
11
+ strategy:
12
+ matrix:
13
+ ruby: [ '2.6', '2.5', '2.4' ]
14
+ steps:
15
+ - uses: actions/checkout@master
16
+ - name: Use Ruby
17
+ uses: actions/setup-ruby@v1
18
+ with:
19
+ ruby-version: ${{ matrix.ruby }}
20
+ architecture: 'x64'
21
+ - name: Update gems
22
+ run: |
23
+ sudo gem install bundler -v "~> 2" --force
24
+ bundle install --jobs 4 --retry 3
25
+ - name: Run specs
26
+ run: |
27
+ bundle exec rake
@@ -0,0 +1,27 @@
1
+ # Auto-generated !!! Do not edit it manually
2
+ # use ci-master https://github.com/metanorma/metanorma-build-scripts
3
+ name: ubuntu
4
+
5
+ on: [push]
6
+
7
+ jobs:
8
+ test-linux:
9
+ name: Test on Ruby ${{ matrix.ruby }} Ubuntu
10
+ runs-on: ubuntu-latest
11
+ strategy:
12
+ matrix:
13
+ ruby: [ '2.6', '2.5', '2.4' ]
14
+ steps:
15
+ - uses: actions/checkout@master
16
+ - name: Use Ruby
17
+ uses: actions/setup-ruby@v1
18
+ with:
19
+ ruby-version: ${{ matrix.ruby }}
20
+ architecture: 'x64'
21
+ - name: Update gems
22
+ run: |
23
+ gem install bundler -v "~> 2"
24
+ bundle install --jobs 4 --retry 3
25
+ - name: Run specs
26
+ run: |
27
+ bundle exec rake
@@ -0,0 +1,30 @@
1
+ # Auto-generated !!! Do not edit it manually
2
+ # use ci-master https://github.com/metanorma/metanorma-build-scripts
3
+ name: windows
4
+
5
+ on: [push]
6
+
7
+ jobs:
8
+ test-windows:
9
+ name: Test on Ruby ${{ matrix.ruby }} Windows
10
+ runs-on: windows-latest
11
+ strategy:
12
+ matrix:
13
+ ruby: [ '2.6', '2.5', '2.4' ]
14
+ steps:
15
+ - uses: actions/checkout@master
16
+ - name: Use Ruby
17
+ uses: actions/setup-ruby@v1
18
+ with:
19
+ ruby-version: ${{ matrix.ruby }}
20
+ architecture: 'x64'
21
+ - name: Update gems
22
+ shell: pwsh
23
+ run: |
24
+ gem install bundler -v "~> 2"
25
+ bundle config --local path vendor/bundle
26
+ bundle update
27
+ bundle install --jobs 4 --retry 3
28
+ - name: Run specs
29
+ run: |
30
+ bundle exec rake
data/Gemfile.lock CHANGED
@@ -1,15 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- relaton-bib (0.3.4)
4
+ relaton-bib (0.3.9)
5
5
  addressable
6
- nokogiri (~> 1.10)
6
+ nokogiri
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- addressable (2.6.0)
12
- public_suffix (>= 2.0.2, < 4.0)
11
+ addressable (2.7.0)
12
+ public_suffix (>= 2.0.2, < 5.0)
13
13
  byebug (11.0.1)
14
14
  debase (0.2.3)
15
15
  debase-ruby_core_source (>= 0.10.2)
@@ -22,7 +22,7 @@ GEM
22
22
  mini_portile2 (2.4.0)
23
23
  nokogiri (1.10.3)
24
24
  mini_portile2 (~> 2.4.0)
25
- public_suffix (3.1.1)
25
+ public_suffix (4.0.1)
26
26
  rake (10.5.0)
27
27
  rspec (3.8.0)
28
28
  rspec-core (~> 3.8.0)
data/lib/relaton_bib.rb CHANGED
@@ -1,8 +1,40 @@
1
1
  require "relaton_bib/version"
2
- require "relaton_bib/bibliographic_item.rb"
2
+ require "relaton_bib/bibliographic_item"
3
+ require "relaton_bib/hit_collection"
4
+ require "relaton_bib/hit"
3
5
 
4
6
  module RelatonBib
5
7
  class Error < StandardError; end
6
8
 
7
9
  class RequestError < StandardError; end
10
+
11
+ class << self
12
+ # @param date [String]
13
+ # @return [Date, NilClass]
14
+ def parse_date(sdate)
15
+ if /(?<date>\w+\s\d{4})/ =~ sdate # February 2012
16
+ Date.strptime(date, "%B %Y")
17
+ elsif /(?<date>\w+\s\d{1,2},\s\d{4})/ =~ sdate # February 11, 2012
18
+ Date.strptime(date, "%B %d, %Y")
19
+ elsif /(?<date>\d{4}-\d{2}-\d{2})/ =~ sdate # 2012-02-11
20
+ Date.parse(date)
21
+ elsif /(?<date>\d{4}-\d{2})/ =~ sdate # 2012-02
22
+ Date.strptime date, "%Y-%m"
23
+ elsif /(?<date>\d{4})/ =~ sdate # 2012
24
+ Date.strptime date, "%Y"
25
+ end
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ # @param array [Array]
32
+ # @return [Array<String>, String]
33
+ def single_element_array(array)
34
+ if array.size > 1
35
+ array.map { |e| e.is_a?(String) ? e : e.to_hash }
36
+ else
37
+ array[0].is_a?(String) ? array[0] : array[0].to_hash
38
+ end
39
+ end
8
40
  end
@@ -45,9 +45,9 @@ module RelatonBib
45
45
 
46
46
  # @return [Hash]
47
47
  def to_hash
48
- hash = { type: type, reference_from: reference_from }
49
- hash[:reference_to] = reference_to if reference_to
48
+ hash = { "type" => type, "reference_from" => reference_from }
49
+ hash["reference_to"] = reference_to if reference_to
50
50
  hash
51
51
  end
52
52
  end
53
- end
53
+ end
@@ -23,7 +23,10 @@ module RelatonBib
23
23
  # @return [Hash]
24
24
  def to_hash
25
25
  hash = super
26
- hash[:type] = type if type
26
+ return hash unless type
27
+
28
+ hash = { "content" => hash } if hash.is_a? String
29
+ hash["type"] = type
27
30
  hash
28
31
  end
29
32
  end
@@ -2,6 +2,8 @@ module RelatonBib
2
2
  # Version
3
3
  class BibliographicItem
4
4
  class Version
5
+ include RelatonBib
6
+
5
7
  # @return [String, NilClass]
6
8
  attr_reader :revision_date
7
9
 
@@ -18,7 +20,7 @@ module RelatonBib
18
20
  # @param builder [Nokogiri::XML::Builder]
19
21
  def to_xml(builder)
20
22
  builder.version do
21
- builder.revision_date revision_date if revision_date
23
+ builder.send("revision-date", revision_date) if revision_date
22
24
  draft.each { |d| builder.draft d }
23
25
  end
24
26
  end
@@ -26,8 +28,8 @@ module RelatonBib
26
28
  # @return [Hash]
27
29
  def to_hash
28
30
  hash = {}
29
- hash[:revision_date] = revision_date if revision_date
30
- hash[:draft] = draft if draft&.any?
31
+ hash["revision_date"] = revision_date if revision_date
32
+ hash["draft"] = single_element_array(draft) if draft&.any?
31
33
  hash
32
34
  end
33
35
  end
@@ -6,8 +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 transmitted copied unchanged circulated
10
- ].freeze
9
+ updated issued transmitted copied unchanged circulated adapted].freeze
11
10
 
12
11
  # @return [String]
13
12
  attr_reader :type
@@ -22,18 +21,18 @@ module RelatonBib
22
21
  attr_reader :on
23
22
 
24
23
  # @param type [String] "published", "accessed", "created", "activated"
24
+ # @param on [String]
25
25
  # @param from [String]
26
26
  # @param to [String]
27
27
  def initialize(type:, on: nil, from: nil, to: nil)
28
28
  raise ArgumentError, "expected :on or :from argument" unless on || from
29
29
 
30
- TYPES.include?(type) or
31
- raise ArgumentError, %{Type "#{type}" is invalid.} unless
30
+ # raise ArgumentError, "invalid type: #{type}" unless TYPES.include? type
32
31
 
33
32
  @type = type
34
- @on = parse_date on
35
- @from = parse_date from
36
- @to = parse_date to
33
+ @on = RelatonBib.parse_date on
34
+ @from = RelatonBib.parse_date from
35
+ @to = RelatonBib.parse_date to
37
36
  end
38
37
 
39
38
  # rubocop:disable Metrics/AbcSize
@@ -54,10 +53,10 @@ module RelatonBib
54
53
 
55
54
  # @return [Hash]
56
55
  def to_hash
57
- hash = { type: type }
58
- hash[:value] = on.to_s if on
59
- hash[:from] = from.to_s if from
60
- hash[:to] = to.to_s if to
56
+ hash = { "type" => type }
57
+ hash["value"] = on.to_s if on
58
+ hash["from"] = from.to_s if from
59
+ hash["to"] = to.to_s if to
61
60
  hash
62
61
  end
63
62
 
@@ -74,19 +73,5 @@ module RelatonBib
74
73
  else date.year
75
74
  end
76
75
  end
77
-
78
- # @params date [String] 'yyyy', 'yyyy-mm', 'yyyy-mm-dd
79
- # @return [Date]
80
- def parse_date(date)
81
- return unless date
82
-
83
- if date =~ /^\d{4}$/
84
- Date.strptime date, "%Y"
85
- elsif date =~ /^\d{4}-\d{2}$/
86
- Date.strptime date, "%Y-%m"
87
- elsif date =~ /\d{4}-\d{2}-\d{2}$/
88
- Date.strptime date, "%Y-%m-%d"
89
- end
90
- end
91
76
  end
92
77
  end
@@ -26,11 +26,12 @@ require "relaton_bib/hash_converter"
26
26
  module RelatonBib
27
27
  # Bibliographic item
28
28
  class BibliographicItem
29
+ include RelatonBib
30
+
29
31
  TYPES = %W[article book booklet conference manual proceedings presentation
30
32
  thesis techreport standard unpublished map electronic\sresource
31
33
  audiovisual film video broadcast graphic_work music patent
32
- inbook incollection inproceedings journal
33
- ].freeze
34
+ inbook incollection inproceedings journal].freeze
34
35
 
35
36
  # @return [String, NilClass]
36
37
  attr_reader :id
@@ -168,7 +169,7 @@ module RelatonBib
168
169
  # @option link [String] :content
169
170
  def initialize(**args)
170
171
  if args[:type] && !TYPES.include?(args[:type])
171
- raise ArgumentError, %{Type "#{args[:type]}" is invalid.}
172
+ warn %{Document type "#{args[:type]}" is invalid.}
172
173
  end
173
174
 
174
175
  @title = (args[:title] || []).map do |t|
@@ -209,7 +210,7 @@ module RelatonBib
209
210
  @language = args.fetch :language, []
210
211
  @script = args.fetch :script, []
211
212
  @status = args[:docstatus]
212
- @relation = DocRelationCollection.new(args[:relation] || [])
213
+ @relation = DocRelationCollection.new(args[:relation] || [])
213
214
  @link = args.fetch(:link, []).map { |s| s.is_a?(Hash) ? TypedUri.new(s) : s }
214
215
  @series = args.fetch :series, []
215
216
  @medium = args[:medium]
@@ -273,32 +274,32 @@ module RelatonBib
273
274
  # @return [Hash]
274
275
  def to_hash
275
276
  hash = {}
276
- hash[:id] = id if id
277
- hash[:title] = title.map(&:to_hash) if title&.any?
278
- hash[:link] = link.map(&:to_hash) if link&.any?
279
- hash[:type] = type if type
280
- hash[:docid] = docidentifier.map(&:to_hash) if docidentifier&.any?
281
- hash[:docnumber] = docnumber if docnumber
282
- hash[:date] = date.map(&:to_hash) if date&.any?
283
- hash[:contributor] = contributor.map(&:to_hash) if contributor&.any?
284
- hash[:edition] = edition if edition
285
- hash[:version] = version.to_hash if version
286
- hash[:biblionote] = biblionote.map(&:to_hash) if biblionote&.any?
287
- hash[:language] = language if language&.any?
288
- hash[:script] = script if script&.any?
289
- hash[:formattedref] = formattedref.to_hash if formattedref
290
- hash[:abstract] = abstract.map(&:to_hash) if abstract&.any?
291
- hash[:docstatus] = status.to_hash if status
292
- hash[:copyright] = copyright.to_hash if copyright
293
- hash[:relation] = relation.map(&:to_hash) if relation&.any?
294
- hash[:series] = series.map(&:to_hash) if series&.any?
295
- hash[:medium] = medium.to_hash if medium
296
- hash[:place] = place if place&.any?
297
- hash[:extent] = extent.map(&:to_hash) if extent&.any?
298
- hash[:accesslocation] = accesslocation if accesslocation&.any?
299
- hash[:classification] = classification.to_hash if classification
300
- hash[:validity] = validity.to_hash if validity
301
- hash[:fetched] = fetched.to_s if fetched
277
+ hash["id"] = id if id
278
+ hash["title"] = single_element_array(title) if title&.any?
279
+ hash["link"] = single_element_array(link) if link&.any?
280
+ hash["type"] = type if type
281
+ hash["docid"] = single_element_array(docidentifier) if docidentifier&.any?
282
+ hash["docnumber"] = docnumber if docnumber
283
+ hash["date"] = single_element_array(date) if date&.any?
284
+ hash["contributor"] = single_element_array(contributor) if contributor&.any?
285
+ hash["edition"] = edition if edition
286
+ hash["version"] = version.to_hash if version
287
+ hash["biblionote"] = single_element_array(biblionote) if biblionote&.any?
288
+ hash["language"] = single_element_array(language) if language&.any?
289
+ hash["script"] = single_element_array(script) if script&.any?
290
+ hash["formattedref"] = formattedref.to_hash if formattedref
291
+ hash["abstract"] = single_element_array(abstract) if abstract&.any?
292
+ hash["docstatus"] = status.to_hash if status
293
+ hash["copyright"] = copyright.to_hash if copyright
294
+ hash["relation"] = single_element_array(relation) if relation&.any?
295
+ hash["series"] = single_element_array(series) if series&.any?
296
+ hash["medium"] = medium.to_hash if medium
297
+ hash["place"] = single_element_array(place) if place&.any?
298
+ hash["extent"] = single_element_array(extent) if extent&.any?
299
+ hash["accesslocation"] = single_element_array(accesslocation) if accesslocation&.any?
300
+ hash["classification"] = classification.to_hash if classification
301
+ hash["validity"] = validity.to_hash if validity
302
+ hash["fetched"] = fetched.to_s if fetched
302
303
  hash
303
304
  end
304
305
 
@@ -21,8 +21,8 @@ module RelatonBib
21
21
 
22
22
  # @return [Hash]
23
23
  def to_hash
24
- hash = { value: value }
25
- hash[:type] = type if type
24
+ hash = { "value" => value }
25
+ hash["type"] = type if type
26
26
  hash
27
27
  end
28
28
  end
@@ -4,17 +4,17 @@ require "relaton_bib/person"
4
4
 
5
5
  # RelatonBib module
6
6
  module RelatonBib
7
-
8
7
  # Contributor's role.
9
8
  class ContributorRole
9
+ include RelatonBib
10
+
10
11
  TYPES = %w[author performer publisher editor adapter translator
11
- distributor
12
- ].freeze
12
+ distributor].freeze
13
13
 
14
14
  # @return [Array<RelatonBib::FormattedString>]
15
15
  attr_reader :description
16
16
 
17
- # @return [ContributorRoleType]
17
+ # @return [Strig]
18
18
  attr_reader :type
19
19
 
20
20
  # @param type [String] allowed types "author", "editor",
@@ -29,6 +29,7 @@ module RelatonBib
29
29
  @description = args.fetch(:description, []).map { |d| FormattedString.new content: d, format: nil }
30
30
  end
31
31
 
32
+ # @param builder [Nokogiri::XML::Builder]
32
33
  def to_xml(builder)
33
34
  builder.role(type: type) do
34
35
  description.each do |d|
@@ -37,18 +38,22 @@ module RelatonBib
37
38
  end
38
39
  end
39
40
 
40
- # @return [Array]
41
+ # @return [Hash, String]
41
42
  def to_hash
42
43
  if description&.any?
43
- [type, description.map(&:content)] if type
44
- else
45
- type if type
44
+ hash = { "description" => single_element_array(description) }
45
+ hash["type"] = type if type
46
+ hash
47
+ elsif type
48
+ type
46
49
  end
47
50
  end
48
51
  end
49
52
 
50
53
  # Contribution info.
51
54
  class ContributionInfo
55
+ include RelatonBib
56
+
52
57
  # @return [Array<RelatonBib::ContributorRole>]
53
58
  attr_reader :role
54
59
 
@@ -71,7 +76,7 @@ module RelatonBib
71
76
  # @return [Hash]
72
77
  def to_hash
73
78
  hash = entity.to_hash
74
- hash[:role] = role.map(&:to_hash) if role&.any?
79
+ hash["role"] = single_element_array(role) if role&.any?
75
80
  hash
76
81
  end
77
82
  end