relaton-bib 1.12.5 → 1.12.6

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: 1c9fcdf11eebba058d61ceabd8c2479615f59e15574137b528cfd7853296c353
4
- data.tar.gz: 429f58fb92119a68f41b828f035e52a7d0acf4d929f87b18c6853db906f166f4
3
+ metadata.gz: ff390021e9158da2d1167e55d988d5dd920c7c9deba9e37838435c7f903d8852
4
+ data.tar.gz: a0fd8d9929ff51df3604243e9dc28770d3b38721950e1886dc6995a90fa95b4c
5
5
  SHA512:
6
- metadata.gz: b9a7ad332dc420595b4ba0f3c06edb2fa598a6c47c934c3c6a837e607541e2fe1d4e0c6e01294aac6b3f9e3cc5e1d3c0eb285f32b5b7a8782aa06c20d31f395c
7
- data.tar.gz: 373bcb27506217f6b170dab13cee9dac7c17dd37efe630dc7fccde29a1cb37c68937ee9c6a7ad101aca75d06bf43b2215d8743551ad70025d47dc685cf4ac092
6
+ metadata.gz: ec5005c4ae8ed03918f6933ed7329990977ab1347eb57626dfdaa1a9dddbd60eada93dc5dfdb365bb1ae06aaf60b8f7fd23ab75837022cbd1f3b6ce4009b797c
7
+ data.tar.gz: 864a6000626e238808513075dc9343debc59a9440e5806092c4af5e90e38e8927e62b3767903e1fc6b65611c8af60e6c4c8b5cb697c91d666f7662501ce0b7ec
@@ -109,8 +109,8 @@ module RelatonBib
109
109
  # @return [Date]
110
110
  def parse_date(date)
111
111
  case date
112
- when /^\d{4}-\d{2}-\d{2}/ then Date.parse(date) # 2012-02-11
113
- when /^\d{4}-\d{2}/ then Date.strptime(date, "%Y-%m") # 2012-02
112
+ when /^\d{4}-\d{1,2}-\d{1,2}/ then Date.parse(date) # 2012-02-11
113
+ when /^\d{4}-\d{1,2}/ then Date.strptime(date, "%Y-%m") # 2012-02
114
114
  when /^\d{4}/ then Date.strptime(date, "%Y") # 2012
115
115
  else date
116
116
  end
@@ -6,15 +6,15 @@ module RelatonBib
6
6
  # @return [RelatonBib::DocumentStatus::Stage]
7
7
  attr_reader :stage
8
8
 
9
- # @return [RelatonBib::DocumentStatus::Stage, NilClass]
9
+ # @return [RelatonBib::DocumentStatus::Stage, nil]
10
10
  attr_reader :substage
11
11
 
12
- # @return [String, NilClass]
12
+ # @return [String, nil]
13
13
  attr_reader :iteration
14
14
 
15
15
  # @param stage [String, Hash, RelatonBib::DocumentStatus::Stage]
16
- # @param substage [String, Hash, NilClass, RelatonBib::DocumentStatus::Stage]
17
- # @param iteration [String, NilClass]
16
+ # @param substage [String, Hash, nil, RelatonBib::DocumentStatus::Stage]
17
+ # @param iteration [String, nil]
18
18
  def initialize(stage:, substage: nil, iteration: nil)
19
19
  @stage = stage_new stage
20
20
  @substage = stage_new substage
@@ -51,7 +51,7 @@ module RelatonBib
51
51
 
52
52
  private
53
53
 
54
- # @param stg [RelatonBib::DocumentStatus::Stage, Hash, String, NilClass]
54
+ # @param stg [RelatonBib::DocumentStatus::Stage, Hash, String, nil]
55
55
  # @return [RelatonBib::DocumentStatus::Stage]
56
56
  def stage_new(stg)
57
57
  case stg
@@ -65,11 +65,11 @@ module RelatonBib
65
65
  # @return [String]
66
66
  attr_reader :value
67
67
 
68
- # @return [String, NilClass]
68
+ # @return [String, nil]
69
69
  attr_reader :abbreviation
70
70
 
71
71
  # @param value [String]
72
- # @param abbreviation [String, NilClass]
72
+ # @param abbreviation [String, nil]
73
73
  def initialize(value:, abbreviation: nil)
74
74
  @value = value
75
75
  @abbreviation = abbreviation
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "1.12.5".freeze
2
+ VERSION = "1.12.6".freeze
3
3
  end
data/lib/relaton_bib.rb CHANGED
@@ -23,20 +23,32 @@ module RelatonBib
23
23
 
24
24
  case date.to_s
25
25
  when /(?<date>\w+\s\d{4})/ # February 2012
26
- d = Date.strptime($~[:date], "%B %Y")
27
- str ? d.strftime("%Y-%m") : d
26
+ format_date $~[:date], "%B %Y", str, "%Y-%m"
28
27
  when /(?<date>\w+\s\d{1,2},\s\d{4})/ # February 11, 2012
29
- d = Date.strptime($~[:date], "%B %d, %Y")
30
- str ? d.strftime("%Y-%m-%d") : d
31
- when /(?<date>\d{4}-\d{2}-\d{2})/ # 2012-02-11
32
- str ? $~[:date] : Date.strptime($~[:date], "%Y-%m-%d")
33
- when /(?<date>\d{4}-\d{2})/ # 2012-02
34
- str ? $~[:date] : Date.strptime($~[:date], "%Y-%m")
28
+ format_date $~[:date], "%B %d, %Y", str, "%Y-%m-%d"
29
+ when /(?<date>\d{4}-\d{1,2}-\d{1,2})/ # 2012-02-03 or 2012-2-3
30
+ format_date $~[:date], "%Y-%m-%d", str
31
+ when /(?<date>\d{4}-\d{1,2})/ # 2012-02 or 2012-2
32
+ format_date $~[:date], "%Y-%m", str
35
33
  when /(?<date>\d{4})/ # 2012
36
- str ? $~[:date] : Date.strptime($~[:date], "%Y")
34
+ format_date $~[:date], "%Y", str
37
35
  end
38
36
  end
39
37
 
38
+ #
39
+ # Parse date string to Date object and format it
40
+ #
41
+ # @param [String] date date string
42
+ # @param [String] format format string
43
+ # @param [Boolean] str return string or Date if true
44
+ #
45
+ # @return [Date, String] date object or formatted date string
46
+ #
47
+ def format_date(date, format, str, outformat = nil)
48
+ date = Date.strptime(date, format)
49
+ str ? date.strftime(outformat || format) : date
50
+ end
51
+
40
52
  # @param arr [NilClass, Array, #is_a?]
41
53
  # @return [Array]
42
54
  def array(arr)
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.12.5
4
+ version: 1.12.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-06 00:00:00.000000000 Z
11
+ date: 2022-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug