iso-bib-item 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/iso_bib_item/bibliographic_date.rb +1 -1
- data/lib/iso_bib_item/contribution_info.rb +4 -4
- data/lib/iso_bib_item/document_relation_collection.rb +11 -1
- data/lib/iso_bib_item/formatted_string.rb +2 -2
- data/lib/iso_bib_item/iso_bibliographic_item.rb +8 -14
- data/lib/iso_bib_item/organization.rb +2 -2
- data/lib/iso_bib_item/person.rb +8 -3
- data/lib/iso_bib_item/version.rb +1 -1
- data/lib/iso_bib_item/xml_parser.rb +48 -25
- 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: ca79f41d3ca54902184130b6a7412f2fa789f980b02e11fa971f53c09b2198d8
|
4
|
+
data.tar.gz: b7200cc75fe060f999f1bb45b75e88b2fdc9e8b7a53681d18809cecfc2006f96
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f77ce607e22d5ae4f3077b8197e6a44086ebeeeb490049be2781f52025e0bbcc2af87d05f9c11e32a372798633d85fc7d9ddcd80b481471f941296157983f89
|
7
|
+
data.tar.gz: 6ce0d5f2ec69c816ecb3df5bb658e01747ec000c7bc2c16280e0c42623510f45c55252330639e088dd4b28a1c93c89b283190ad3d31019cde22c1db83c3f26b4
|
data/Gemfile.lock
CHANGED
@@ -15,9 +15,9 @@ module IsoBibItem
|
|
15
15
|
# @param type [String] allowed types "author", "editor",
|
16
16
|
# "cartographer", "publisher"
|
17
17
|
# @param description [Array<String>]
|
18
|
-
def initialize(
|
19
|
-
@type =
|
20
|
-
@description =
|
18
|
+
def initialize(*args)
|
19
|
+
@type = args.fetch 0
|
20
|
+
@description = args.fetch(1, []).map { |d| FormattedString.new content: d, type: nil }
|
21
21
|
end
|
22
22
|
|
23
23
|
def to_xml(builder)
|
@@ -44,7 +44,7 @@ module IsoBibItem
|
|
44
44
|
# @param role [Array<String>]
|
45
45
|
def initialize(entity:, role: ['publisher'])
|
46
46
|
@entity = entity
|
47
|
-
@role = role.map { |r| ContributorRole.new(r) }
|
47
|
+
@role = role.map { |r| ContributorRole.new(*r) }
|
48
48
|
end
|
49
49
|
|
50
50
|
def to_xml(builder)
|
@@ -49,6 +49,13 @@ module IsoBibItem
|
|
49
49
|
@reference_from = reference_from
|
50
50
|
@reference_to = reference_to
|
51
51
|
end
|
52
|
+
|
53
|
+
def to_xml(builder)
|
54
|
+
builder.locality(type: type) do
|
55
|
+
builder.referenceFrom { reference_from.to_xml(builder) }
|
56
|
+
builder.referenceTo reference_to if reference_to
|
57
|
+
end
|
58
|
+
end
|
52
59
|
end
|
53
60
|
|
54
61
|
# Documett relation
|
@@ -79,11 +86,14 @@ module IsoBibItem
|
|
79
86
|
# @param builder [Nokogiri::XML::Builder]
|
80
87
|
def to_xml(builder)
|
81
88
|
builder.relation(type: type) do
|
82
|
-
if @bibitem.nil?
|
89
|
+
if @bibitem.nil?
|
83
90
|
builder.bibitem do
|
84
91
|
builder.formattedref identifier
|
85
92
|
# builder.docidentifier identifier
|
86
93
|
end
|
94
|
+
bib_locality.each do |l|
|
95
|
+
l.to_xml builder
|
96
|
+
end
|
87
97
|
else
|
88
98
|
@bibitem.to_xml(builder, {})
|
89
99
|
end
|
@@ -14,13 +14,13 @@ module IsoBibItem
|
|
14
14
|
# @param type [String] the format type, default "plain"
|
15
15
|
# available types "plain", "html", "dockbook", "tei", "asciidoc",
|
16
16
|
# "markdown", "isodoc"
|
17
|
-
def initialize(content:, language
|
17
|
+
def initialize(content:, language: nil, script: nil, type: 'plain')
|
18
18
|
super(content, language, script)
|
19
19
|
@type = type
|
20
20
|
end
|
21
21
|
|
22
22
|
def to_xml(builder)
|
23
|
-
builder.parent[
|
23
|
+
builder.parent["format"] = type if type
|
24
24
|
super
|
25
25
|
end
|
26
26
|
end
|
@@ -121,7 +121,7 @@ module IsoBibItem
|
|
121
121
|
|
122
122
|
# Bibliographic item.
|
123
123
|
class IsoBibliographicItem < BibliographicItem
|
124
|
-
# @return [IsoBibItem::IsoDocumentId]
|
124
|
+
# @return [Array<IsoBibItem::IsoDocumentId>]
|
125
125
|
attr_reader :docidentifier
|
126
126
|
|
127
127
|
# @return [String]
|
@@ -241,7 +241,7 @@ module IsoBibItem
|
|
241
241
|
def shortref(identifier, **opts)
|
242
242
|
pubdate = dates.select { |d| d.type == "published" }
|
243
243
|
year = if opts[:no_year] || pubdate.empty? then ""
|
244
|
-
else
|
244
|
+
else ":" + pubdate&.first&.on&.year&.to_s
|
245
245
|
end
|
246
246
|
year += ": All Parts" if opts[:all_parts] || @all_parts
|
247
247
|
|
@@ -268,11 +268,11 @@ module IsoBibItem
|
|
268
268
|
private
|
269
269
|
|
270
270
|
# @return [Array<IsoBibItem::ContributionInfo>]
|
271
|
-
def publishers
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
end
|
271
|
+
# def publishers
|
272
|
+
# @contributors.select do |c|
|
273
|
+
# c.role.select { |r| r.type == 'publisher' }.any?
|
274
|
+
# end
|
275
|
+
# end
|
276
276
|
|
277
277
|
def makeid(id, attribute, delim = '')
|
278
278
|
return nil if attribute && !@id_attribute
|
@@ -298,13 +298,7 @@ module IsoBibItem
|
|
298
298
|
builder.fetched fetched
|
299
299
|
title.each { |t| t.to_xml builder }
|
300
300
|
link.each { |s| s.to_xml builder }
|
301
|
-
|
302
|
-
@docidentifier.each do |i|
|
303
|
-
attrs = {}
|
304
|
-
attrs[:type] = i.type if i.type
|
305
|
-
# builder.docidentifier shortref(i, opts.merge(no_year: true)), **attrs
|
306
|
-
builder.docidentifier i.id, **attrs
|
307
|
-
end
|
301
|
+
docidentifier.each { |i| i.to_xml builder }
|
308
302
|
dates.each { |d| d.to_xml builder, opts }
|
309
303
|
contributors.each do |c|
|
310
304
|
builder.contributor do
|
@@ -47,11 +47,11 @@ module IsoBibItem
|
|
47
47
|
# @param abbreviation [String]
|
48
48
|
# @param url [String]
|
49
49
|
# @TODO identifier
|
50
|
-
def initialize(name:, abbreviation: nil, url: nil)
|
50
|
+
def initialize(name:, abbreviation: nil, url: nil, identifiers: [])
|
51
51
|
super(url: url)
|
52
52
|
@name = name.is_a?(Array) ? name.map { |n| hash2locstr(n) } : [hash2locstr(name)]
|
53
53
|
@abbreviation = LocalizedString.new abbreviation
|
54
|
-
@identifiers =
|
54
|
+
@identifiers = identifiers
|
55
55
|
end
|
56
56
|
|
57
57
|
# @param builder [Nokogiri::XML::Builder]
|
data/lib/iso_bib_item/person.rb
CHANGED
@@ -73,6 +73,10 @@ module IsoBibItem
|
|
73
73
|
@type = type
|
74
74
|
@value = value
|
75
75
|
end
|
76
|
+
|
77
|
+
def to_xml(builder)
|
78
|
+
builder.identifier value, type: type
|
79
|
+
end
|
76
80
|
end
|
77
81
|
|
78
82
|
# Person class.
|
@@ -88,11 +92,11 @@ module IsoBibItem
|
|
88
92
|
|
89
93
|
# @param name [IsoBibItem::FullName]
|
90
94
|
# @param affiliation [Array<IsoBibItem::Affiliation>]
|
91
|
-
def initialize(name:, affiliation: [], contacts:)
|
95
|
+
def initialize(name:, affiliation: [], contacts:, identifiers: [])
|
92
96
|
super(contacts: contacts)
|
93
97
|
@name = name
|
94
|
-
@affiliation
|
95
|
-
@identifiers =
|
98
|
+
@affiliation = affiliation
|
99
|
+
@identifiers = identifiers
|
96
100
|
end
|
97
101
|
|
98
102
|
# @param builder [Nokogiri::XML::Builder]
|
@@ -100,6 +104,7 @@ module IsoBibItem
|
|
100
104
|
builder.person do
|
101
105
|
name.to_xml builder
|
102
106
|
affiliation.each { |a| a.to_xml builder }
|
107
|
+
identifiers.each { |id| id.to_xml builder }
|
103
108
|
contacts.each { |contact| contact.to_xml builder }
|
104
109
|
end
|
105
110
|
end
|
data/lib/iso_bib_item/version.rb
CHANGED
@@ -49,8 +49,8 @@ module IsoBibItem
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def fetch_titles(doc)
|
52
|
-
doc.xpath(
|
53
|
-
titl = t.text.split
|
52
|
+
doc.xpath("/bibitem/title").map do |t|
|
53
|
+
titl = t.text.sub("[ -- ]", "").split " -- "
|
54
54
|
case titl.size
|
55
55
|
when 0
|
56
56
|
intro, main, part = nil, "", nil
|
@@ -95,49 +95,61 @@ module IsoBibItem
|
|
95
95
|
end
|
96
96
|
|
97
97
|
def get_org(org)
|
98
|
-
names = org.xpath(
|
98
|
+
names = org.xpath("name").map do |n|
|
99
99
|
{ content: n.text, language: n[:language], script: n[:script] }
|
100
100
|
end
|
101
|
+
identifiers = org.xpath("./identifier").map do |i|
|
102
|
+
IsoBibItem::OrgIdentifier.new(i[:type], i.text)
|
103
|
+
end
|
101
104
|
IsoBibItem::Organization.new(name: names,
|
102
|
-
abbreviation: org.at(
|
103
|
-
url: org.at(
|
105
|
+
abbreviation: org.at("abbreviation")&.text,
|
106
|
+
url: org.at("uri")&.text,
|
107
|
+
identifiers: identifiers)
|
104
108
|
end
|
105
109
|
|
106
110
|
def get_person(person)
|
107
|
-
name = person.at
|
108
|
-
affilations = person.xpath(
|
109
|
-
org = a.at
|
111
|
+
name = person.at "./name/completename"
|
112
|
+
affilations = person.xpath("./affiliation").map do |a|
|
113
|
+
org = a.at "./organization"
|
110
114
|
IsoBibItem::Affilation.new get_org(org)
|
111
115
|
end
|
112
|
-
|
113
|
-
|
114
|
-
|
116
|
+
|
117
|
+
contacts = person.xpath("./address | ./phone | ./email | ./uri").map do |contact|
|
118
|
+
if contact.name == "address"
|
119
|
+
streets = contact.xpath("./street").map(&:text)
|
115
120
|
IsoBibItem::Address.new(
|
116
121
|
street: streets,
|
117
|
-
city:
|
118
|
-
state:
|
119
|
-
country:
|
120
|
-
postcode:
|
122
|
+
city: contact.at("./city").text,
|
123
|
+
state: contact.at("./state").text,
|
124
|
+
country: contact.at("./country").text,
|
125
|
+
postcode: contact.at("./postcode").text,
|
121
126
|
)
|
122
127
|
else
|
123
|
-
contact
|
124
|
-
IsoBibItem::Contact.new(type: contact[:name], value: contact.text)
|
128
|
+
IsoBibItem::Contact.new(type: contact.name, value: contact.text)
|
125
129
|
end
|
126
130
|
end
|
131
|
+
|
132
|
+
identifiers = person.xpath("./identifier").map do |pi|
|
133
|
+
IsoBibItem::PersonIdentifier.new pi[:type], pi.text
|
134
|
+
end
|
135
|
+
|
127
136
|
completename = IsoBibItem::LocalizedString.new(name.text, name[:language])
|
128
137
|
IsoBibItem::Person.new(
|
129
138
|
name: IsoBibItem::FullName.new(completename: completename),
|
130
139
|
affiliation: affilations,
|
131
|
-
contacts: contacts
|
140
|
+
contacts: contacts,
|
141
|
+
identifiers: identifiers,
|
132
142
|
)
|
133
143
|
end
|
134
144
|
|
135
145
|
def fetch_contributors(doc)
|
136
|
-
doc.xpath(
|
137
|
-
entity = if (org = c.at
|
138
|
-
elsif (person = c.at
|
146
|
+
doc.xpath("/bibitem/contributor").map do |c|
|
147
|
+
entity = if (org = c.at "./organization") then get_org(org)
|
148
|
+
elsif (person = c.at "./person") then get_person(person)
|
139
149
|
end
|
140
|
-
|
150
|
+
role_descr = c.xpath("./role/description").map &:text
|
151
|
+
IsoBibItem::ContributionInfo.new entity: entity,
|
152
|
+
role: [[c.at("role")[:type], role_descr]]
|
141
153
|
end
|
142
154
|
end
|
143
155
|
|
@@ -186,9 +198,20 @@ module IsoBibItem
|
|
186
198
|
end
|
187
199
|
|
188
200
|
def fetch_relations(doc)
|
189
|
-
doc.xpath(
|
190
|
-
|
191
|
-
|
201
|
+
doc.xpath("/bibitem/relation").map do |r|
|
202
|
+
localities = r.xpath("./locality").map do |l|
|
203
|
+
ref_to = (rt = l.at("./referenceTo")) ? LocalizedString.new(rt.text) : nil
|
204
|
+
BibItemLocality.new(
|
205
|
+
l[:type],
|
206
|
+
LocalizedString.new(l.at("./referenceFrom").text),
|
207
|
+
ref_to
|
208
|
+
)
|
209
|
+
end
|
210
|
+
DocumentRelation.new(
|
211
|
+
type: r[:type],
|
212
|
+
identifier: r&.at("./bibitem/formattedref | ./bibitem/docidentifier")&.text,
|
213
|
+
bib_locality: localities,
|
214
|
+
)
|
192
215
|
end
|
193
216
|
end
|
194
217
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iso-bib-item
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|