relaton-bib 1.5.pre1 → 1.6.1

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
  SHA256:
3
- metadata.gz: 1c135ae20e6dedad964161c4688f955bc1f6ff9945e36dcfbb4aaed73bf6d6bf
4
- data.tar.gz: 7e1775460d12c0c2b8e4014cced56a7dbd84abf215c0882e34a11c198977d28c
3
+ metadata.gz: e1acb1bee569016f446bebcaeac0a98d1491d19be9a87dbd072cabec368c1aea
4
+ data.tar.gz: 48897d74a02ea1fe1d2578ac8fbe9f6bd89d1f0fb47b19000f75dbc7697caac7
5
5
  SHA512:
6
- metadata.gz: f6ca89938617badf59e7e92503e1b08a87428ea0cadca42af71e93c9e528a5d2f9fd1a2f7c1a90893233db16cad05c46295561f42962c3fcdb8402cbf331e723
7
- data.tar.gz: 82204e17e4ce3dc1df5555eea3f7817b1cbfa4d1f1bd2de22ef3499ea84539dbce1ef114e651a303367ae35b1a78823b043dc954d907f1717b3305662d692312
6
+ metadata.gz: ef1c0e62f60371c2416af0d0436165ba187d95004a2b8e6401b0c56ac98c0a4a4d1a75a4ec44f65bc5c50130e38d453107bbc370c291c23697efb8aae5f1c422
7
+ data.tar.gz: 2c7a9ccf203fe180282339700b580b575db35ce712901784b3c0e72005279561ad0e9218202b2d4f1a9ed609fc9118412a1ae9a7919fb913015efae150e2eeb1
@@ -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"/>
@@ -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
@@ -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
@@ -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
@@ -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.pre1".freeze
2
+ VERSION = "1.6.1".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.pre1
4
+ version: 1.6.1
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-08 00:00:00.000000000 Z
11
+ date: 2020-11-16 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: