relaton-bib 1.5.pre → 1.6.0

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: 718bae79646e15f68243d997e053ed614d8309dafad8cbb8e9d0189d49198171
4
- data.tar.gz: e54d51485d37662aa2507d074f859b896277d13fe298158ce84faf9570e037bc
3
+ metadata.gz: 68c51d5b5aa557ccabc5d856b7409d7d8adcd0b9c78f34dc1a057ca54e72190a
4
+ data.tar.gz: f7aba8995fc0ea2021f02956db58e8f3b32525b887e558584036dab471371cda
5
5
  SHA512:
6
- metadata.gz: 630aee8ec416f891616c5efcdd068994422bfca2415f57a9e211fec53bece058c51af62220301dd7dc547c5fcde34852f5fc970256d6a845040fd58745ab5ca7
7
- data.tar.gz: 7dfc99a09a5e896a76c27fed1c0dcc8ff02b126d51c019831532849626a972a28f2f1593f1d5e59b3a8ced5b97264a6d2abdb876f2874b2a3aad037017aa2757
6
+ metadata.gz: fbf3250413e9c23af6b001532523f11ba94ecb67e0e913d35d6f79180a9a51f7700becd426d51a948db222b52c7b03fe5e7f643536c134eb78fe95a30e1d157c
7
+ data.tar.gz: 31b2762918ff1692d12cc1cfafdd830142a1e79b33d7b172ef18897d7bd9d10e31291a6f1eee1c7a37851dc7bd45e50fceafdee73d8298af6ec3874f34c1be0a
@@ -32,6 +32,8 @@ jobs:
32
32
  - name: Update gems
33
33
  run: |
34
34
  sudo gem install bundler --force
35
+ ruby -v | grep 2.5 && bundle config set build.debase --with-cflags="-Wno-error=implicit-function-declaration"
36
+ ruby -v | grep 2.5 && bundle config set build.ruby-debug-ide --with-cflags="-Wno-error=implicit-function-declaration"
35
37
  bundle install --jobs 4 --retry 3
36
38
  - name: Run specs
37
39
  run: |
@@ -42,7 +42,6 @@
42
42
  </define>
43
43
  <define name="xref">
44
44
  <element name="xref">
45
- <!-- attribute target { xsd:IDREF }, -->
46
45
  <attribute name="target">
47
46
  <data type="string">
48
47
  <param name="pattern">\i\c*|\c+#\c+</param>
@@ -864,6 +863,13 @@
864
863
  </define>
865
864
  <define name="standard-document">
866
865
  <element name="standard-document">
866
+ <attribute name="version"/>
867
+ <attribute name="type">
868
+ <choice>
869
+ <value>semantic</value>
870
+ <value>presentation</value>
871
+ </choice>
872
+ </attribute>
867
873
  <ref name="bibdata"/>
868
874
  <optional>
869
875
  <ref name="boilerplate"/>
@@ -1,6 +1,7 @@
1
1
  require "forwardable"
2
2
  require "relaton_bib/version"
3
3
  require "relaton_bib/deep_dup"
4
+ require "relaton_bib/localized_string"
4
5
  require "relaton_bib/bibliographic_item"
5
6
  require "relaton_bib/hit_collection"
6
7
  require "relaton_bib/hit"
@@ -12,21 +13,24 @@ module RelatonBib
12
13
 
13
14
  class << self
14
15
  # @param date [String, Integer, Date]
15
- # @return [Date, NilClass]
16
- def parse_date(date) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
16
+ # @param str [Boolean]
17
+ # @return [Date, nil]
18
+ def parse_date(date, str = true) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
17
19
  return date if date.is_a?(Date)
18
20
 
19
- sdate = date.to_s
20
- case sdate
21
+ case date.to_s
21
22
  when /(?<date>\w+\s\d{4})/ # February 2012
22
- Date.strptime($~[:date], "%B %Y")
23
+ d = Date.strptime($~[:date], "%B %Y")
24
+ str ? d.strftime("%Y-%m") : d
23
25
  when /(?<date>\w+\s\d{1,2},\s\d{4})/ # February 11, 2012
24
- Date.strptime($~[:date], "%B %d, %Y")
26
+ d = Date.strptime($~[:date], "%B %d, %Y")
27
+ str ? d.strftime("%Y-%m-%d") : d
25
28
  when /(?<date>\d{4}-\d{2}-\d{2})/ # 2012-02-11
26
- Date.parse($~[:date])
29
+ str ? $~[:date] : Date.strptime($~[:date], "%Y-%m-%d")
27
30
  when /(?<date>\d{4}-\d{2})/ # 2012-02
28
- Date.strptime date, "%Y-%m"
29
- when /(?<date>\d{4})/ then Date.strptime $~[:date], "%Y" # 2012
31
+ str ? $~[:date] : Date.strptime($~[:date], "%Y-%m")
32
+ when /(?<date>\d{4})/ # 2012
33
+ str ? $~[:date] : Date.strptime($~[:date], "%Y")
30
34
  end
31
35
  end
32
36
  end
@@ -3,7 +3,7 @@ module RelatonBib
3
3
  extend Forwardable
4
4
 
5
5
  def_delegators :@array, :[], :first, :last, :empty?, :any?, :size,
6
- :each, :map, :detect, :length
6
+ :each, :map, :reduce, :detect, :length
7
7
 
8
8
  def initialize(notes)
9
9
  @array = notes
@@ -12,15 +12,6 @@ module RelatonBib
12
12
  # @return [String]
13
13
  attr_reader :type
14
14
 
15
- # @return [Date]
16
- attr_reader :from
17
-
18
- # @return [Date]
19
- attr_reader :to
20
-
21
- # @return [Date]
22
- attr_reader :on
23
-
24
15
  # @param type [String] "published", "accessed", "created", "activated"
25
16
  # @param on [String]
26
17
  # @param from [String]
@@ -36,6 +27,21 @@ module RelatonBib
36
27
  @to = RelatonBib.parse_date to
37
28
  end
38
29
 
30
+ # @param part [Symbol] :year, :month, :day, :date
31
+ # @return [String, Date, nil]
32
+ def from(part = nil)
33
+ d = instance_variable_get "@#{__callee__}".to_sym
34
+ return d unless part
35
+
36
+ date = parse_date(d)
37
+ return date if part == :date
38
+
39
+ date.send part
40
+ end
41
+
42
+ alias_method :to, :from
43
+ alias_method :on, :from
44
+
39
45
  # rubocop:disable Metrics/AbcSize
40
46
 
41
47
  # @param builder [Nokogiri::XML::Builder]
@@ -77,14 +83,24 @@ module RelatonBib
77
83
  private
78
84
 
79
85
  # Formats date
80
- # @param date [Time]
81
- # @param format [Symbol, nil] :full (yyyy-mm-dd), :short (yyyy-mm) or nil (yyyy)
86
+ # @param date [String]
87
+ # @param format [Symbol, nil] :full (yyyy-mm-dd), :short (yyyy-mm) or nil
82
88
  # @return [String]
83
89
  def date_format(date, format = nil)
84
90
  case format
85
- when :short then date.strftime "%Y-%m"
86
- when :full then date.strftime "%Y-%m-%d"
87
- else date.year
91
+ when :short then parse_date(date).strftime "%Y-%m"
92
+ when :full then parse_date(date).strftime "%Y-%m-%d"
93
+ else date
94
+ end
95
+ end
96
+
97
+ # @param date [String]
98
+ # @return [Date]
99
+ def parse_date(date)
100
+ case date
101
+ when /\d{4}-\d{2}-\d{2}/ then Date.parse(date) # 2012-02-11
102
+ when /\d{4}-\d{2}/ then Date.strptime(date, "%Y-%m") # 2012-02
103
+ when /\d{4}/ then Date.strptime(date, "%Y") # 2012
88
104
  end
89
105
  end
90
106
  end
@@ -292,7 +292,7 @@ module RelatonBib
292
292
  def shortref(identifier, **opts) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/AbcSize,Metrics/PerceivedComplexity
293
293
  pubdate = date.select { |d| d.type == "published" }
294
294
  year = if opts[:no_year] || pubdate.empty? then ""
295
- else ":" + pubdate&.first&.on&.year.to_s
295
+ else ":" + pubdate&.first&.on(:year).to_s
296
296
  end
297
297
  year += ": All Parts" if opts[:all_parts] || @all_parts
298
298
 
@@ -610,8 +610,8 @@ module RelatonBib
610
610
  date.each do |d|
611
611
  case d.type
612
612
  when "published"
613
- item.year = d.on.year
614
- item.month = d.on.month
613
+ item.year = d.on :year
614
+ item.month = d.on :month
615
615
  when "accessed" then item.urldate = d.on.to_s
616
616
  end
617
617
  end
@@ -678,7 +678,7 @@ module RelatonBib
678
678
  title.to_xml **opts
679
679
  formattedref&.to_xml builder
680
680
  link.each { |s| s.to_xml builder }
681
- docidentifier.each { |di| di.to_xml builder }
681
+ docidentifier.each { |di| di.to_xml **opts }
682
682
  builder.docnumber docnumber if docnumber
683
683
  date.each { |d| d.to_xml builder, **opts }
684
684
  contributor.each do |c|
@@ -45,10 +45,15 @@ module RelatonBib
45
45
  #
46
46
  # Add docidentifier xml element
47
47
  #
48
- # @param [Nokogiri::XML::Builder] builder
49
- #
50
- def to_xml(builder)
51
- element = builder.docidentifier id
48
+ # @param opts [Hash]
49
+ # @option opts [Nokogiri::XML::Builder] :builder XML builder
50
+ # @option opts [String] :lang language
51
+ def to_xml(**opts) # rubocop:disable Metrics/AbcSize
52
+ lid = if type == "URN" && opts[:lang]
53
+ id.sub %r{(?<=:)(?:\w{2},)*?(#{opts[:lang]})(?:,\w{2})*}, '\1'
54
+ else id
55
+ end
56
+ element = opts[:builder].docidentifier lid
52
57
  element[:type] = type if type
53
58
  element[:scope] = scope if scope
54
59
  end
@@ -66,11 +71,12 @@ module RelatonBib
66
71
  # @return [String]
67
72
  def to_asciibib(prefix = "", count = 1)
68
73
  pref = prefix.empty? ? prefix : prefix + "."
74
+ return "#{pref}docid:: #{id}\n" unless type || scope
75
+
69
76
  out = count > 1 ? "#{pref}docid::\n" : ""
70
77
  out += "#{pref}docid.type:: #{type}\n" if type
71
78
  out += "#{pref}docid.scope:: #{scope}\n" if scope
72
- out += "#{pref}docid.id:: #{id}\n"
73
- out
79
+ out + "#{pref}docid.id:: #{id}\n"
74
80
  end
75
81
 
76
82
  private
@@ -6,7 +6,7 @@ module RelatonBib
6
6
  extend Forwardable
7
7
 
8
8
  def_delegators :@array, :<<, :[], :first, :last, :empty?, :any?, :size,
9
- :each, :detect, :map, :length
9
+ :each, :detect, :map, :reduce, :length
10
10
 
11
11
  # @param relation [Array<RelatonBib::DocumentRelation, Hash>]
12
12
  # @option relation [String] :type
@@ -1,7 +1,4 @@
1
1
  # frozen_string_literal: true
2
-
3
- require "relaton_bib/localized_string"
4
-
5
2
  module RelatonBib
6
3
  # Document status.
7
4
  class DocumentStatus
@@ -125,7 +125,7 @@ module RelatonBib
125
125
 
126
126
  ret[:docid] = array(ret[:docid])
127
127
  ret[:docid]&.each_with_index do |id, i|
128
- type = id[:type] || id[:id].match(/^\w+/)&.to_s
128
+ type = id[:type] || id[:id].match(/^\w+\s/)&.to_s
129
129
  ret[:docid][i] = DocumentIdentifier.new(id: id[:id], type: type,
130
130
  scope: id[:scope])
131
131
  end
@@ -4,7 +4,8 @@ module RelatonBib
4
4
  class HitCollection
5
5
  extend Forwardable
6
6
 
7
- def_delegators :@array, :<<, :[], :first, :empty?, :any?, :size, :each, :each_slice
7
+ def_delegators :@array, :<<, :[], :first, :empty?, :any?, :size, :each,
8
+ :each_slice, :reduce
8
9
 
9
10
  # @return [TrueClass, FalseClass]
10
11
  attr_reader :fetched
@@ -3,7 +3,8 @@ module RelatonBib
3
3
  include RelatonBib
4
4
  extend Forwardable
5
5
 
6
- def_delegators :@collection, :any?, :size, :[], :detect
6
+ def_delegators :@collection, :any?, :size, :[], :detect, :map, :each,
7
+ :reduce
7
8
 
8
9
  # @param collection [Array<RelatonBib::StructuredIdentifier>]
9
10
  def initialize(collection)
@@ -3,7 +3,7 @@ module RelatonBib
3
3
  extend Forwardable
4
4
 
5
5
  def_delegators :@array, :[], :first, :last, :empty?, :any?, :size,
6
- :each, :detect, :map, :length
6
+ :each, :detect, :map, :reduce, :length
7
7
 
8
8
  # @param title [Array<RelatonBib::TypedTitleString, Hash>]
9
9
  def initialize(title = [])
@@ -30,6 +30,12 @@ module RelatonBib
30
30
  TypedTitleStringCollection.new(titles.select { |t| yield t })
31
31
  end
32
32
 
33
+ # @param init [Array, Hash]
34
+ # @return [RelatonBib::TypedTitleStringCollection]
35
+ # def reduce(init)
36
+ # self.class.new @array.reduce(init) { |m, t| yield m, t }
37
+ # end
38
+
33
39
  # @param title [RelatonBib::TypedTitleString]
34
40
  # @return [self]
35
41
  def <<(title)
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "1.5.pre".freeze
2
+ VERSION = "1.6.0".freeze
3
3
  end
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: 1.5.pre
4
+ version: 1.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-06 00:00:00.000000000 Z
11
+ date: 2020-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -259,9 +259,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
259
259
  version: 2.4.0
260
260
  required_rubygems_version: !ruby/object:Gem::Requirement
261
261
  requirements:
262
- - - ">"
262
+ - - ">="
263
263
  - !ruby/object:Gem::Version
264
- version: 1.3.1
264
+ version: '0'
265
265
  requirements: []
266
266
  rubygems_version: 3.0.6
267
267
  signing_key: