relaton-bib 1.6.0 → 1.6.1

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: 68c51d5b5aa557ccabc5d856b7409d7d8adcd0b9c78f34dc1a057ca54e72190a
4
- data.tar.gz: f7aba8995fc0ea2021f02956db58e8f3b32525b887e558584036dab471371cda
3
+ metadata.gz: e1acb1bee569016f446bebcaeac0a98d1491d19be9a87dbd072cabec368c1aea
4
+ data.tar.gz: 48897d74a02ea1fe1d2578ac8fbe9f6bd89d1f0fb47b19000f75dbc7697caac7
5
5
  SHA512:
6
- metadata.gz: fbf3250413e9c23af6b001532523f11ba94ecb67e0e913d35d6f79180a9a51f7700becd426d51a948db222b52c7b03fe5e7f643536c134eb78fe95a30e1d157c
7
- data.tar.gz: 31b2762918ff1692d12cc1cfafdd830142a1e79b33d7b172ef18897d7bd9d10e31291a6f1eee1c7a37851dc7bd45e50fceafdee73d8298af6ec3874f34c1be0a
6
+ metadata.gz: ef1c0e62f60371c2416af0d0436165ba187d95004a2b8e6401b0c56ac98c0a4a4d1a75a4ec44f65bc5c50130e38d453107bbc370c291c23697efb8aae5f1c422
7
+ data.tar.gz: 2c7a9ccf203fe180282339700b580b575db35ce712901784b3c0e72005279561ad0e9218202b2d4f1a9ed609fc9118412a1ae9a7919fb913015efae150e2eeb1
@@ -15,7 +15,7 @@ module RelatonBib
15
15
  # @param date [String, Integer, Date]
16
16
  # @param str [Boolean]
17
17
  # @return [Date, nil]
18
- def parse_date(date, str = true) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
18
+ def parse_date(date, str = true) # rubocop:disable Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity,Metrics/AbcSize
19
19
  return date if date.is_a?(Date)
20
20
 
21
21
  case date.to_s
@@ -31,12 +31,12 @@ module RelatonBib
31
31
  # @return [String, Date, nil]
32
32
  def from(part = nil)
33
33
  d = instance_variable_get "@#{__callee__}".to_sym
34
- return d unless part
34
+ return d unless part && d
35
35
 
36
36
  date = parse_date(d)
37
37
  return date if part == :date
38
38
 
39
- date.send part
39
+ date.is_a?(Date) ? date.send(part) : date
40
40
  end
41
41
 
42
42
  alias_method :to, :from
@@ -87,20 +87,23 @@ module RelatonBib
87
87
  # @param format [Symbol, nil] :full (yyyy-mm-dd), :short (yyyy-mm) or nil
88
88
  # @return [String]
89
89
  def date_format(date, format = nil)
90
- case format
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
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
95
97
  end
96
98
 
97
99
  # @param date [String]
98
100
  # @return [Date]
99
101
  def parse_date(date)
100
102
  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
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
104
107
  end
105
108
  end
106
109
  end
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "1.6.0".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.6.0
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-11-13 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