relaton-bib 1.5.0 → 1.6.2

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: 6731fb438a67250f0ea4b70e14aa783a6034595f7e6677f4c97c7158b787355e
4
- data.tar.gz: b91531a725bd08256e4c41cb9c61f670195f4e4dd00665b034182e7b990aa228
3
+ metadata.gz: a7f6ef2eec280ac48d171fa25bc4c88d2df63692b5736823868f1751af971f3d
4
+ data.tar.gz: 78e4a52cb0e1d1ce66404af62d2e7f79f27634acbf84094a19e0f593affbdb5a
5
5
  SHA512:
6
- metadata.gz: f8cc251a4c9dd90633c123862bdd09b8e7a3745080733aa36db751c26367b66558598d035b0aed131d095cd6d6a67df56e0ec988a4e18e674b64fdf3b216c061
7
- data.tar.gz: fa3bb5f8290df770a2607ba65812fa8998650d2cfee2b22170964cf13b8286dd25f162e239e43b7ee5c9ca6e4efd42b819e10a40da77856044c308f03b02796a
6
+ metadata.gz: 226ead0669d2f060d24b541c8e0eab0d9357b0a697b96572aed3b68b539b97d9f2662f76669a7e0167eedd3fcbc1bdf8ff65e3d3135facdb1531619749095cba
7
+ data.tar.gz: 2a333a1a1ba8aa6683a6abc6f97d521c3be510cbaa7455483266e62523764cf6e04de0b909a0109c21c0c1e5aab5fc224140f97b0f2b60c66d55535e5f434c12
@@ -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: |
@@ -13,21 +13,24 @@ module RelatonBib
13
13
 
14
14
  class << self
15
15
  # @param date [String, Integer, Date]
16
- # @return [Date, NilClass]
17
- 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,Metrics/PerceivedComplexity,Metrics/AbcSize
18
19
  return date if date.is_a?(Date)
19
20
 
20
- sdate = date.to_s
21
- case sdate
21
+ case date.to_s
22
22
  when /(?<date>\w+\s\d{4})/ # February 2012
23
- Date.strptime($~[:date], "%B %Y")
23
+ d = Date.strptime($~[:date], "%B %Y")
24
+ str ? d.strftime("%Y-%m") : d
24
25
  when /(?<date>\w+\s\d{1,2},\s\d{4})/ # February 11, 2012
25
- Date.strptime($~[:date], "%B %d, %Y")
26
+ d = Date.strptime($~[:date], "%B %d, %Y")
27
+ str ? d.strftime("%Y-%m-%d") : d
26
28
  when /(?<date>\d{4}-\d{2}-\d{2})/ # 2012-02-11
27
- Date.parse($~[:date])
29
+ str ? $~[:date] : Date.strptime($~[:date], "%Y-%m-%d")
28
30
  when /(?<date>\d{4}-\d{2})/ # 2012-02
29
- Date.strptime date, "%Y-%m"
30
- 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")
31
34
  end
32
35
  end
33
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
@@ -62,9 +62,10 @@ module RelatonBib
62
62
  # @return [String]
63
63
  def to_asciibib(prefix = "", count = 1)
64
64
  pref = prefix.empty? ? prefix : prefix + "."
65
- out = count > 1 ? "#{pref}biblionote::\n" : ""
66
- out + "#{pref}biblionote.type:: #{type}\n" if type
67
- out += super "#{pref}biblionote"
65
+ has_attrs = !(type.nil? || type.empty?)
66
+ out = count > 1 && has_attrs ? "#{pref}biblionote::\n" : ""
67
+ out += "#{pref}biblionote.type:: #{type}\n" if type
68
+ out += super "#{pref}biblionote", 1, has_attrs
68
69
  out
69
70
  end
70
71
  end
@@ -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 && d
35
+
36
+ date = parse_date(d)
37
+ return date if part == :date
38
+
39
+ date.is_a?(Date) ? date.send(part) : date
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,27 @@ 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
- case format
85
- when :short then date.strftime "%Y-%m"
86
- when :full then date.strftime "%Y-%m-%d"
87
- else date.year
90
+ tmplt = case format
91
+ when :short then "%Y-%m"
92
+ when :full then "%Y-%m-%d"
93
+ else return date
94
+ end
95
+ d = parse_date(date)
96
+ d.is_a?(Date) ? d.strftime(tmplt) : d
97
+ end
98
+
99
+ # @param date [String]
100
+ # @return [Date]
101
+ def parse_date(date)
102
+ case date
103
+ when /^\d{4}-\d{2}-\d{2}/ then Date.parse(date) # 2012-02-11
104
+ when /^\d{4}-\d{2}/ then Date.strptime(date, "%Y-%m") # 2012-02
105
+ when /^\d{4}/ then Date.strptime(date, "%Y") # 2012
106
+ else date
88
107
  end
89
108
  end
90
109
  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
@@ -81,8 +81,11 @@ module RelatonBib
81
81
  attr_reader :entity
82
82
 
83
83
  # @param entity [RelatonBib::Person, RelatonBib::Organization]
84
- # @param role [Array<String>]
85
- def initialize(entity:, role: [{ type: "publisher" }])
84
+ # @param role [Array<Hash>]
85
+ def initialize(entity:, role: [])
86
+ if role.empty?
87
+ role << { type: entity.is_a?(Person) ? "author" : "publisher" }
88
+ end
86
89
  @entity = entity
87
90
  @role = role.map { |r| ContributorRole.new(**r) }
88
91
  end
@@ -71,11 +71,12 @@ module RelatonBib
71
71
  # @return [String]
72
72
  def to_asciibib(prefix = "", count = 1)
73
73
  pref = prefix.empty? ? prefix : prefix + "."
74
+ return "#{pref}docid:: #{id}\n" unless type || scope
75
+
74
76
  out = count > 1 ? "#{pref}docid::\n" : ""
75
77
  out += "#{pref}docid.type:: #{type}\n" if type
76
78
  out += "#{pref}docid.scope:: #{scope}\n" if scope
77
- out += "#{pref}docid.id:: #{id}\n"
78
- out
79
+ out + "#{pref}docid.id:: #{id}\n"
79
80
  end
80
81
 
81
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
@@ -44,7 +44,8 @@ module RelatonBib
44
44
  # @param prefix [String]
45
45
  # @param count [Integer] number of elements
46
46
  # @return [String]
47
- def to_asciibib(prefix = "", count = 1)
47
+ def to_asciibib(prefix = "", count = 1, has_attrs = false)
48
+ has_attrs ||= !(format.nil? || format.empty?)
48
49
  pref = prefix.empty? ? prefix : prefix + "."
49
50
  # out = count > 1 ? "#{prefix}::\n" : ""
50
51
  out = super
@@ -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
@@ -77,9 +77,13 @@ module RelatonBib
77
77
  # @param prefix [String]
78
78
  # @param count [Integer] number of elements
79
79
  # @return [String]
80
- def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
80
+ def to_asciibib(prefix = "", count = 1, has_attrs = false) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/MethodLength
81
81
  pref = prefix.empty? ? prefix : prefix + "."
82
82
  if content.is_a? String
83
+ unless language&.any? || script&.any? || has_attrs
84
+ return "#{prefix}:: #{content}\n"
85
+ end
86
+
83
87
  out = count > 1 ? "#{prefix}::\n" : ""
84
88
  out += "#{pref}content:: #{content}\n"
85
89
  language&.each { |l| out += "#{pref}language:: #{l}\n" }
@@ -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)
@@ -156,7 +162,7 @@ module RelatonBib
156
162
  pref = prefix.empty? ? prefix : prefix + "."
157
163
  out = count > 1 ? "#{pref}title::\n" : ""
158
164
  out += "#{pref}title.type:: #{type}\n" if type
159
- out += title.to_asciibib "#{pref}title"
165
+ out += title.to_asciibib "#{pref}title", 1, !(type.nil? || type.empty?)
160
166
  out
161
167
  end
162
168
  end
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "1.5.0".freeze
2
+ VERSION = "1.6.2".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.0
4
+ version: 1.6.2
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-09 00:00:00.000000000 Z
11
+ date: 2020-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug