relaton-bib 1.2.2 → 1.2.4

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: 60c49a41357c85d67963be4c8260759919e4ec11b14444e0ebaea3eb71c51597
4
- data.tar.gz: 7f1e174522173f072112e5230fefb1d490f4d7aae472f36c92a7fe82c7bb2303
3
+ metadata.gz: 2c556856365ed3b55dfead00fa129508a6d541aaa04fa96d4a37997761d77aaf
4
+ data.tar.gz: 1e819257d4ee84d00bd6a0634a6abbc91b19ed6d9854275c0b9c04db4bb43c1a
5
5
  SHA512:
6
- metadata.gz: 85aebc56a9f88e43dcac88b74a951557536e183549ef32340493cdeea30612a7443bd09472886e7d0b4494538c57b1109eebc9fd2c940f7df94e0bebbb02eb02
7
- data.tar.gz: 470d434701c6c2ba04ffd444ac7f4e056b7cd3220b1fa6121f63bee273a97056643156ab455e0ed526cd981d124ae4535b3f70b0aa754139e3c541fe51ae7615
6
+ metadata.gz: a65cc8f9435f61a0313d744f3827a55a91e7ccb7edc1d143f318d38cb2fb07b7fa75b7cdb871133c631d4deee778ba1c552811b11aa4aec479370cfcbe28d87f
7
+ data.tar.gz: 3c105c0244fd7e2f3fbdca1a9fd0626560f9d6e5f754743ff23530311885f0fca8c31e70cfcaae1961cc0ee957908854063d2972390885bbe46a3beb8179d194
@@ -10,24 +10,27 @@ module RelatonBib
10
10
  class RequestError < StandardError; end
11
11
 
12
12
  class << self
13
- # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
13
+ # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
14
14
 
15
- # @param date [String]
15
+ # @param date [String, Integer, Date]
16
16
  # @return [Date, NilClass]
17
- def parse_date(sdate)
18
- if sdate.is_a?(Date) then sdate
19
- elsif /(?<date>\w+\s\d{4})/ =~ sdate # February 2012
20
- Date.strptime(date, "%B %Y")
21
- elsif /(?<date>\w+\s\d{1,2},\s\d{4})/ =~ sdate # February 11, 2012
22
- Date.strptime(date, "%B %d, %Y")
23
- elsif /(?<date>\d{4}-\d{2}-\d{2})/ =~ sdate # 2012-02-11
24
- Date.parse(date)
25
- elsif /(?<date>\d{4}-\d{2})/ =~ sdate # 2012-02
17
+ def parse_date(date)
18
+ return date if date.is_a?(Date)
19
+
20
+ sdate = date.to_s
21
+ case sdate
22
+ when /(?<date>\w+\s\d{4})/ # February 2012
23
+ Date.strptime($~[:date], "%B %Y")
24
+ when /(?<date>\w+\s\d{1,2},\s\d{4})/ # February 11, 2012
25
+ Date.strptime($~[:date], "%B %d, %Y")
26
+ when /(?<date>\d{4}-\d{2}-\d{2})/ # 2012-02-11
27
+ Date.parse($~[:date])
28
+ when /(?<date>\d{4}-\d{2})/ # 2012-02
26
29
  Date.strptime date, "%Y-%m"
27
- elsif /(?<date>\d{4})/ =~ sdate then Date.strptime date, "%Y" # 2012
30
+ when /(?<date>\d{4})/ then Date.strptime $~[:date], "%Y" # 2012
28
31
  end
29
32
  end
30
- # rubocop:enable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
33
+ # rubocop:enable Metrics/CyclomaticComplexity, Metrics/MethodLength
31
34
  end
32
35
 
33
36
  private
@@ -375,18 +375,29 @@ module RelatonBib
375
375
  end
376
376
  end
377
377
 
378
- # rubocop:disable Metrics/AbcSize
379
-
380
378
  # @param ret [Hash]
381
379
  def validity_hash_to_bib(ret)
382
380
  return unless ret[:validity]
383
381
 
384
- ret[:validity][:begins] && b = Time.parse(ret[:validity][:begins].to_s)
385
- ret[:validity][:ends] && e = Time.parse(ret[:validity][:ends].to_s)
386
- ret[:validity][:revision] && r = Time.parse(ret[:validity][:revision].to_s)
382
+ b = parse_validity_time(ret[:validity], :begins)
383
+ e = parse_validity_time(ret[:validity], :ends)
384
+ r = parse_validity_time(ret[:validity], :revision)
387
385
  ret[:validity] = Validity.new(begins: b, ends: e, revision: r)
388
386
  end
389
- # rubocop:enable Metrics/AbcSize
387
+
388
+ def parse_validity_time(val, period)
389
+ t = val[period]&.to_s
390
+ return unless t
391
+
392
+ p = period == :ends ? -1 : 1
393
+ case t
394
+ when /^\d{4}$/
395
+ Date.new(t.to_i, p, p).to_time
396
+ when /^(?<year>\d{4})-(?<month>\d{1,2})$/
397
+ Date.new($~[:year].to_i, $~[:month].to_i, p).to_time
398
+ else Time.parse t
399
+ end
400
+ end
390
401
 
391
402
  # @param ret [Hash]
392
403
  def editorialgroup_hash_to_bib(ret)
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "1.2.2".freeze
2
+ VERSION = "1.2.4".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.2.2
4
+ version: 1.2.4
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-06-29 00:00:00.000000000 Z
11
+ date: 2020-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug