relaton-bib 1.5.1 → 1.6.pre1

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: de6c6f8d155863ad2ac349a7f700057304a853d49bef05cccef7d0b18f077efa
4
- data.tar.gz: 3507f0906a299bfa8cd08a052077bc3293f1814414d29f3a1ffe53979bdd1532
3
+ metadata.gz: c9741b425d8415304b51078b9a7c649560abccdecbec0ead58986994209b4baf
4
+ data.tar.gz: 9ec3425ae7f42bc668be546058c6d7b7ff5a4be4bd345b9f0f74c4ca26be2db5
5
5
  SHA512:
6
- metadata.gz: a36b8aaca8049117da0b969df10e60ea09d3788b5e1e337073bb9b2a38add00319343a813db4e4b403f7a88a391b2c404c50bdd360aee7d5da9334c8d3a8b0ba
7
- data.tar.gz: 5192b67352e20fbdbcc9ab491cd9161a2bde3c526ad99ccd8829f1c967e2d4eda12ff92be2022e218269d5a0fe9aaa2925519bd8c49cb9c8faebbf124e87a610
6
+ metadata.gz: 66bd1804ab23745be33b2990dec11c84e7a9e1b70e192604e131d298cf88893bff94f20648085099c7505d5b201d54886f6e96eeb9d5ef4694495794e7203242
7
+ data.tar.gz: c0d5e9ce4b7dba3f22f1834017f58afbf2a826be3eefbe67e6bfd6ca0fb9fe1310dc7dc55f71b783137d5f3df2011c4f54cb717bb07aa798cc28c535b94ccc34
@@ -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
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
@@ -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
@@ -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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "1.5.1".freeze
2
+ VERSION = "1.6.pre1".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.1
4
+ version: 1.6.pre1
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-27 00:00:00.000000000 Z
11
+ date: 2020-11-11 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: '0'
264
+ version: 1.3.1
265
265
  requirements: []
266
266
  rubygems_version: 3.0.6
267
267
  signing_key: