relaton-bib 1.11.1 → 1.11.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.adoc +5 -1
- data/grammars/biblio.rng +38 -9
- data/lib/relaton_bib/place.rb +120 -28
- data/lib/relaton_bib/version.rb +1 -1
- data/lib/relaton_bib/xml_parser.rb +20 -1
- 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: d15360baaf96bbd8ba4bb079f5c1ed71b2d1a3c04a709b7b26122b10ea6e998d
|
4
|
+
data.tar.gz: ea64b85cfe56d2bac01881c246877f9ffb5329bf108dbffbe9e9ce789352a244
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c94693cbcd3a935883d608a80af6d8660ebf08a079898a4658ed057fd5ce7f84e93631f33579f8fbc6696b80f1413fac49b2dd48af120d5c60c7e104ebbf1b01
|
7
|
+
data.tar.gz: e98dca1228dff147f05e7ea460a95ea909137fa49fdd38fdc9af3c9147e3030e0ef1c65906f79dac5f108b5d2d0107410c52bf8d584a75401f01fd112a8205cb
|
data/README.adoc
CHANGED
@@ -213,7 +213,11 @@ item = RelatonBib::BibliographicItem.new(
|
|
213
213
|
),
|
214
214
|
place: [
|
215
215
|
"bib place",
|
216
|
-
RelatonBib::Place.new(
|
216
|
+
RelatonBib::Place.new(
|
217
|
+
city: "Geneva",
|
218
|
+
region: [RelatonBib::Place::RegionType.new(name: "Region")],
|
219
|
+
country: [RelatonBib::Place::RegionType.new(name: "Switzeland", iso: "SH", recommended: true)],
|
220
|
+
)
|
217
221
|
],
|
218
222
|
extent: [
|
219
223
|
RelatonBib::BibItemLocality.new("section", "Reference from", "Reference to"),
|
data/grammars/biblio.rng
CHANGED
@@ -527,7 +527,7 @@
|
|
527
527
|
</define>
|
528
528
|
<define name="LocalityType">
|
529
529
|
<data type="string">
|
530
|
-
<param name="pattern">section|clause|part|paragraph|chapter|page|whole|table|annex|figure|note|list|example|volume|issue|time|anchor|locality:[a-zA-Z0-9_]+</param>
|
530
|
+
<param name="pattern">section|clause|part|paragraph|chapter|page|title|line|whole|table|annex|figure|note|list|example|volume|issue|time|anchor|locality:[a-zA-Z0-9_]+</param>
|
531
531
|
</data>
|
532
532
|
</define>
|
533
533
|
<define name="referenceFrom">
|
@@ -851,17 +851,46 @@
|
|
851
851
|
</define>
|
852
852
|
<define name="bplace">
|
853
853
|
<element name="place">
|
854
|
-
<
|
855
|
-
<
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
854
|
+
<choice>
|
855
|
+
<text/>
|
856
|
+
<group>
|
857
|
+
<ref name="bibliocity"/>
|
858
|
+
<zeroOrMore>
|
859
|
+
<ref name="biblioregion"/>
|
860
|
+
</zeroOrMore>
|
861
|
+
<zeroOrMore>
|
862
|
+
<ref name="bibliocountry"/>
|
863
|
+
</zeroOrMore>
|
864
|
+
</group>
|
865
|
+
</choice>
|
866
|
+
</element>
|
867
|
+
</define>
|
868
|
+
<define name="bibliocity">
|
869
|
+
<element name="city">
|
862
870
|
<text/>
|
863
871
|
</element>
|
864
872
|
</define>
|
873
|
+
<define name="biblioregion">
|
874
|
+
<element name="region">
|
875
|
+
<ref name="RegionType"/>
|
876
|
+
</element>
|
877
|
+
</define>
|
878
|
+
<define name="bibliocountry">
|
879
|
+
<element name="country">
|
880
|
+
<ref name="RegionType"/>
|
881
|
+
</element>
|
882
|
+
</define>
|
883
|
+
<define name="RegionType">
|
884
|
+
<optional>
|
885
|
+
<attribute name="iso"/>
|
886
|
+
</optional>
|
887
|
+
<optional>
|
888
|
+
<attribute name="recommended">
|
889
|
+
<data type="boolean"/>
|
890
|
+
</attribute>
|
891
|
+
</optional>
|
892
|
+
<text/>
|
893
|
+
</define>
|
865
894
|
<define name="bprice">
|
866
895
|
<element name="price">
|
867
896
|
<attribute name="currency"/>
|
data/lib/relaton_bib/place.rb
CHANGED
@@ -1,49 +1,141 @@
|
|
1
1
|
module RelatonBib
|
2
2
|
class Place
|
3
|
-
# @return [String]
|
4
|
-
attr_reader :name
|
5
|
-
|
6
|
-
# @return [
|
7
|
-
attr_reader :
|
8
|
-
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
3
|
+
# @return [String, nil]
|
4
|
+
attr_reader :name, :city
|
5
|
+
|
6
|
+
# @return [Array<RelatonBib::Place::RegionType>]
|
7
|
+
attr_reader :region, :country
|
8
|
+
|
9
|
+
#
|
10
|
+
# Initialize place.
|
11
|
+
#
|
12
|
+
# @param name [String, nil] name of place, name or city should be provided
|
13
|
+
# @param city [String, nil] name of city, city or name should be provided
|
14
|
+
# @param region [Array<RelatonBib::Place::RegionType>] region of place
|
15
|
+
# @param country [Array<RelatonBib::Place::RegionType>] country of place
|
16
|
+
#
|
17
|
+
def initialize(name: nil, city: nil, region: [], country: []) # rubocop:disable Metrics/CyclomaticComplexity
|
18
|
+
if name.nil? && city.nil?
|
19
|
+
raise ArgumentError, "`name` or `city` should be provided"
|
20
|
+
end
|
21
|
+
|
22
|
+
@name = name
|
23
|
+
@city = city
|
24
|
+
@region = region.map { |r| r.is_a?(Hash) ? RegionType.new(**r) : r }
|
25
|
+
@country = country.map { |c| c.is_a?(Hash) ? RegionType.new(**c) : c }
|
16
26
|
end
|
17
27
|
|
28
|
+
#
|
29
|
+
# Render place as XML.
|
30
|
+
#
|
18
31
|
# @param builder [Nologiri::XML::Builder]
|
32
|
+
#
|
19
33
|
def to_xml(builder)
|
20
|
-
|
21
|
-
|
22
|
-
|
34
|
+
if name
|
35
|
+
builder.place name
|
36
|
+
else
|
37
|
+
builder.place do |b|
|
38
|
+
b.city city
|
39
|
+
region.each { |r| b.region { r.to_xml b } }
|
40
|
+
country.each { |c| b.country { c.to_xml b } }
|
41
|
+
end
|
42
|
+
end
|
23
43
|
end
|
24
44
|
|
45
|
+
#
|
46
|
+
# Render place as Hash.
|
47
|
+
#
|
25
48
|
# @return [Hash]
|
49
|
+
#
|
26
50
|
def to_hash
|
27
|
-
if
|
28
|
-
hash = { "name" => name }
|
29
|
-
hash["uri"] = uri if uri
|
30
|
-
hash["region"] = region if region
|
31
|
-
hash
|
51
|
+
if name then name
|
32
52
|
else
|
33
|
-
|
53
|
+
hash = { "city" => city }
|
54
|
+
hash["region"] = region.map(&:to_hash) if region.any?
|
55
|
+
hash["country"] = country.map(&:to_hash) if country.any?
|
56
|
+
hash
|
34
57
|
end
|
35
58
|
end
|
36
59
|
|
60
|
+
#
|
61
|
+
# Render place as AsciiBib.
|
62
|
+
#
|
37
63
|
# @param prefix [String]
|
38
64
|
# @param count [Integer] number of places
|
65
|
+
#
|
39
66
|
# @return [Stirng]
|
40
|
-
|
41
|
-
|
67
|
+
#
|
68
|
+
def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize
|
69
|
+
pref = prefix.empty? ? "place" : "#{prefix}.place"
|
42
70
|
out = count > 1 ? "#{pref}::\n" : ""
|
43
|
-
|
44
|
-
|
45
|
-
out += "#{pref}.
|
46
|
-
out
|
71
|
+
return "#{out}#{pref}.name:: #{name}\n" if name
|
72
|
+
|
73
|
+
out += "#{pref}.city:: #{city}\n"
|
74
|
+
out += region.map { |r| r.to_asciibib("#{pref}.region", region.size) }.join
|
75
|
+
out + country.map { |c| c.to_asciibib("#{pref}.country", country.size) }.join
|
76
|
+
end
|
77
|
+
|
78
|
+
class RegionType
|
79
|
+
# @return [Strign] name of region
|
80
|
+
attr_reader :name
|
81
|
+
|
82
|
+
# @return [Strign, nil] ISO code of region
|
83
|
+
attr_reader :iso
|
84
|
+
|
85
|
+
# @return [Boolean, nil] <description>
|
86
|
+
attr_reader :recommended
|
87
|
+
|
88
|
+
#
|
89
|
+
# Initialize region type.
|
90
|
+
#
|
91
|
+
# @param [String] name name of region
|
92
|
+
# @param [String, nil] iso ISO code of region
|
93
|
+
# @param [Boolean, nil] recommended recommended region
|
94
|
+
#
|
95
|
+
def initialize(name:, iso: nil, recommended: nil)
|
96
|
+
@name = name
|
97
|
+
@iso = iso
|
98
|
+
@recommended = recommended
|
99
|
+
end
|
100
|
+
|
101
|
+
#
|
102
|
+
# Render region type as XML.
|
103
|
+
#
|
104
|
+
# @param [Nokogiri::XML::Builder] builder XML builder
|
105
|
+
#
|
106
|
+
def to_xml(builder)
|
107
|
+
builder.parent["iso"] = iso if iso
|
108
|
+
builder.parent["recommended"] = recommended.to_s unless recommended.nil?
|
109
|
+
builder.text name
|
110
|
+
end
|
111
|
+
|
112
|
+
#
|
113
|
+
# Render region type as Hash.
|
114
|
+
#
|
115
|
+
# @return [Hash] region type as Hash
|
116
|
+
#
|
117
|
+
def to_hash
|
118
|
+
hash = { "name" => name }
|
119
|
+
hash["iso"] = iso if iso
|
120
|
+
hash["recommended"] = recommended unless recommended.nil?
|
121
|
+
hash
|
122
|
+
end
|
123
|
+
|
124
|
+
#
|
125
|
+
# Render region type as AsciiBib.
|
126
|
+
#
|
127
|
+
# @param [String] pref prefix
|
128
|
+
# @param [Integer] count number of region types
|
129
|
+
#
|
130
|
+
# @return [String] region type as AsciiBib
|
131
|
+
#
|
132
|
+
def to_asciibib(pref, count = 1) # rubocop:disable Metrics/AbcSize
|
133
|
+
out = count > 1 ? "#{pref}::\n" : ""
|
134
|
+
out += "#{pref}.name:: #{name}\n"
|
135
|
+
out += "#{pref}.iso:: #{iso}\n" if iso
|
136
|
+
out += "#{pref}.recommended:: #{recommended}\n" if recommended
|
137
|
+
out
|
138
|
+
end
|
47
139
|
end
|
48
140
|
end
|
49
141
|
end
|
data/lib/relaton_bib/version.rb
CHANGED
@@ -72,7 +72,26 @@ module RelatonBib
|
|
72
72
|
|
73
73
|
def fetch_place(item)
|
74
74
|
item.xpath("./place").map do |pl|
|
75
|
-
|
75
|
+
if (city = pl.at("./city"))
|
76
|
+
Place.new(city: city.text, region: create_region_country(pl),
|
77
|
+
country: create_region_country(pl, "country"))
|
78
|
+
else
|
79
|
+
Place.new(name: pl.text)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
#
|
85
|
+
# Create region or country from place element
|
86
|
+
#
|
87
|
+
# @param [Nokogiri::XML::Element] place place element
|
88
|
+
# @param [String] node name of the node to parse
|
89
|
+
#
|
90
|
+
# @return [Array<RelatonBib::Place::RegionType>] <description>
|
91
|
+
#
|
92
|
+
def create_region_country(place, node = "region")
|
93
|
+
place.xpath("./#{node}").map do |r|
|
94
|
+
Place::RegionType.new(name: r.text, iso: r[:iso], recommended: r[:recommended])
|
76
95
|
end
|
77
96
|
end
|
78
97
|
|
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.11.
|
4
|
+
version: 1.11.2
|
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-04-
|
11
|
+
date: 2022-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|