relaton-bib 1.12.4 → 1.12.7
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 +4 -4
- data/lib/relaton_bib/bibliographic_date.rb +2 -2
- data/lib/relaton_bib/document_relation.rb +1 -1
- data/lib/relaton_bib/document_relation_collection.rb +16 -1
- data/lib/relaton_bib/document_status.rb +7 -7
- data/lib/relaton_bib/localized_string.rb +16 -11
- data/lib/relaton_bib/typed_title_string.rb +1 -1
- data/lib/relaton_bib/version.rb +1 -1
- data/lib/relaton_bib/xml_parser.rb +1 -1
- data/lib/relaton_bib.rb +22 -9
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: be4b986a04f391a2e552c13d8ee897e73c398f3acb27deda3bb203da627f585b
|
|
4
|
+
data.tar.gz: 05540e11934396b938df0c902d926c37b1c49c8aa215b7888827bb42d19d4042
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f82094e85351832f3738216ce8ba72c68f7f26e9bcd7379cbe49b2e9a2bc0318ce1d4507462d3dbfed61ba57fc9bc692daf4998cbc84fb3bc2f54a14bed7e72a
|
|
7
|
+
data.tar.gz: 66de7c5f7b612c203694d6adacb0fdbf09dd34380f24bfe6e3d298f50d61d52af844f2803f8e75644839ce0b256726db55fc9058a649f9f42c8c3198f6e279ab
|
|
@@ -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,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,
|
|
9
|
+
# @return [RelatonBib::DocumentStatus::Stage, nil]
|
|
10
10
|
attr_reader :substage
|
|
11
11
|
|
|
12
|
-
# @return [String,
|
|
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,
|
|
17
|
-
# @param iteration [String,
|
|
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,
|
|
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,
|
|
68
|
+
# @return [String, nil]
|
|
69
69
|
attr_reader :abbreviation
|
|
70
70
|
|
|
71
71
|
# @param value [String]
|
|
72
|
-
# @param abbreviation [String,
|
|
72
|
+
# @param abbreviation [String, nil]
|
|
73
73
|
def initialize(value:, abbreviation: nil)
|
|
74
74
|
@value = value
|
|
75
75
|
@abbreviation = abbreviation
|
|
@@ -68,14 +68,17 @@ module RelatonBib
|
|
|
68
68
|
# @return [String] encoded content
|
|
69
69
|
#
|
|
70
70
|
def encode(cnt) # rubocop:disable Metrics/MethodLength
|
|
71
|
-
|
|
71
|
+
return unless cnt
|
|
72
|
+
|
|
73
|
+
# regex = /(?<prf>.*?)(?<xml><(?<tag>\w+)>.*<\/\k<tag>>)(?<sfx>.*)/m
|
|
74
|
+
regex = /(?<prf>.*?)(?<xml><(?<tag>\w+)[^>]*(?:>.*<\/\k<tag>)?>)(?<rest>.*)/m
|
|
72
75
|
if cnt.match(regex)
|
|
73
76
|
prf = Regexp.last_match(:prf).lstrip
|
|
74
77
|
xml = Regexp.last_match[:xml]
|
|
75
|
-
|
|
76
|
-
parts = xml.scan(/\s*<(?<tago>\w+)>(?<cnt1>.*?)(
|
|
78
|
+
rest = Regexp.last_match(:rest).rstrip
|
|
79
|
+
parts = xml.scan(/\s*<(?<tago>\w+)(?<attrs>[^>]*)>(?:(?<cnt1>.*?)(?=<\/\w+>|<\w+[^>]*>))?|(?<cnt2>.*?)<\/(?<tagc>\w+)>/)
|
|
77
80
|
out = scan_xml parts
|
|
78
|
-
"#{escp(prf)}#{out}#{
|
|
81
|
+
"#{escp(prf)}#{out}#{encode(rest)}"
|
|
79
82
|
else
|
|
80
83
|
escp cnt
|
|
81
84
|
end
|
|
@@ -84,22 +87,24 @@ module RelatonBib
|
|
|
84
87
|
#
|
|
85
88
|
# Scan XML and escape HTML entities.
|
|
86
89
|
#
|
|
87
|
-
# @param [Array<Array<String,
|
|
90
|
+
# @param [Array<Array<String,nil>>] parts XML parts
|
|
88
91
|
#
|
|
89
92
|
# @return [String] output string
|
|
90
93
|
#
|
|
91
94
|
def scan_xml(parts) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/MethodLength
|
|
92
95
|
return "" unless parts.any? && parts.first[0]
|
|
93
96
|
|
|
94
|
-
tago, cnt1, = parts.shift
|
|
95
|
-
if tago && tago == parts.first
|
|
96
|
-
_, _, cnt2, tagc = parts.shift
|
|
97
|
-
"<#{tago}>#{escp(cnt1)}#{escp(cnt2)}</#{tagc}>"
|
|
97
|
+
tago, attrs, cnt1, = parts.shift
|
|
98
|
+
if tago && tago == parts.first&.last
|
|
99
|
+
_, _, _, cnt2, tagc = parts.shift
|
|
100
|
+
"<#{tago}#{attrs}>#{escp(cnt1)}#{escp(cnt2)}</#{tagc}>"
|
|
101
|
+
elsif tago && attrs && attrs[-1] == "/"
|
|
102
|
+
"<#{tago}#{attrs}>"
|
|
98
103
|
elsif tago
|
|
99
104
|
inr = scan_xml parts
|
|
100
|
-
_, _, cnt2, tagc = parts.shift
|
|
105
|
+
_, _, _, cnt2, tagc = parts.shift
|
|
101
106
|
if tago == tagc
|
|
102
|
-
"<#{tago}>#{escp(cnt1)}#{inr}#{escp(cnt2)}</#{tagc}>"
|
|
107
|
+
"<#{tago}#{attrs}>#{escp(cnt1)}#{inr}#{escp(cnt2)}</#{tagc}>"
|
|
103
108
|
else
|
|
104
109
|
"#{escp("<#{tago}>#{cnt1}")}#{inr}#{escp("#{cnt2}</#{tagc}>")}"
|
|
105
110
|
end
|
data/lib/relaton_bib/version.rb
CHANGED
data/lib/relaton_bib.rb
CHANGED
|
@@ -23,20 +23,33 @@ module RelatonBib
|
|
|
23
23
|
|
|
24
24
|
case date.to_s
|
|
25
25
|
when /(?<date>\w+\s\d{4})/ # February 2012
|
|
26
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
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
|
-
|
|
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 if true in other case return Date
|
|
44
|
+
# @param [String, nil] outformat output format
|
|
45
|
+
#
|
|
46
|
+
# @return [Date, String] date object or formatted date string
|
|
47
|
+
#
|
|
48
|
+
def format_date(date, format, str, outformat = nil)
|
|
49
|
+
date = Date.strptime(date, format)
|
|
50
|
+
str ? date.strftime(outformat || format) : date
|
|
51
|
+
end
|
|
52
|
+
|
|
40
53
|
# @param arr [NilClass, Array, #is_a?]
|
|
41
54
|
# @return [Array]
|
|
42
55
|
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.
|
|
4
|
+
version: 1.12.7
|
|
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-
|
|
11
|
+
date: 2022-08-16 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: byebug
|