relaton-bib 1.12.3 → 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: 3610adb6319fa59f2a67b10146c3e976c7c827d91df441b504de6534cb285020
4
- data.tar.gz: 75f324998da686277dee651003ba6bb2e0dea57bcb170e8db0e0566f12a45ca3
3
+ metadata.gz: ff390021e9158da2d1167e55d988d5dd920c7c9deba9e37838435c7f903d8852
4
+ data.tar.gz: a0fd8d9929ff51df3604243e9dc28770d3b38721950e1886dc6995a90fa95b4c
5
5
  SHA512:
6
- metadata.gz: 4d732c577746afab2468f58404b93ab207999425ab8f9069589622ea3b89172ed9230390bdb033652440c478ab2b723977ec62064e92ce5202cde0dc753ca3c5
7
- data.tar.gz: 3ac992c12c4dd00a17314a5f49ea79d82f8a66b1e8707087a2e52c17f863ea547d793f5d429fa2d63024ca6f9b22ce258e35fe55c4bfc4c947a81dcb44bd5209
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
@@ -251,7 +251,10 @@ module RelatonBib
251
251
  # "front/author[not(@surname)][not(@fullname)]/organization",
252
252
  # ).map do |org|
253
253
  org = contrib.at("./organization")
254
- name = ORGNAMES[org.text] || org.text
254
+ orgname = org.text.strip
255
+ return if orgname.empty?
256
+
257
+ name = ORGNAMES[orgname] || orgname
255
258
  { entity: new_org(name, org[:abbrev]), role: [contributor_role(contrib)] }
256
259
  # end
257
260
  end
@@ -17,7 +17,7 @@ module RelatonBib
17
17
  ].freeze
18
18
 
19
19
  # @return [String]
20
- attr_reader :type
20
+ attr_accessor :type
21
21
 
22
22
  # @return [RelatonBib::FormattedString, NilClass]
23
23
  attr_reader :description
@@ -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, :reduce, :length, :unshift
9
+ :each, :detect, :map, :reduce, :length, :unshift, :max_by
10
10
 
11
11
  # @param relation [Array<RelatonBib::DocumentRelation, Hash>]
12
12
  # @option relation [String] :type
@@ -21,6 +21,21 @@ module RelatonBib
21
21
  @array = relation.map { |r| r.is_a?(Hash) ? DocumentRelation.new(**r) : r }
22
22
  end
23
23
 
24
+ #
25
+ # Returns new DocumentRelationCollection with selected relations.
26
+ #
27
+ # @example Select relations with type "obsoletes"
28
+ # relations.select { |r| r.type == "obsoletes" }
29
+ # #=> <RelatonBib::DocRelationCollection:0x00007f9a0191d5f0 @array=[...]>
30
+ #
31
+ # @return [RelatonBib::DocRelationCollection] new DocumentRelationCollection
32
+ # with selected relations
33
+ #
34
+ def select(&block)
35
+ arr = @array.select(&block)
36
+ self.class.new arr
37
+ end
38
+
24
39
  # @todo We don't have replace type anymore. Suppose we should update this
25
40
  # method or delete it.
26
41
  #
@@ -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.3".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.3
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-07-26 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