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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4ae2b39dbf95400893806d73fb3f395b51d365bc4c8fe97c6f07794e0faa993b
4
- data.tar.gz: 77d3006345ebec0522b6594b184893784ed448df28e0cb591ca0334c330b9351
3
+ metadata.gz: ca79f41d3ca54902184130b6a7412f2fa789f980b02e11fa971f53c09b2198d8
4
+ data.tar.gz: b7200cc75fe060f999f1bb45b75e88b2fdc9e8b7a53681d18809cecfc2006f96
5
5
  SHA512:
6
- metadata.gz: e2c57e2c286f7bb66cdf797e66ad27620f8796a04e505d0105c59097d12df39c83f66bbeb21e97d3a5fd25310e63be860fe9d544dfb35b3edf21d7a878971176
7
- data.tar.gz: 64458e12f087b7ec84d23bc5fe5363f75b8b6e070cfc2cff0c5a246a2c9920d254ec9eabc8066da5f3039c090f9040afef369bfe25da8a0d8be40c0cc916c488
6
+ metadata.gz: 4f77ce607e22d5ae4f3077b8197e6a44086ebeeeb490049be2781f52025e0bbcc2af87d05f9c11e32a372798633d85fc7d9ddcd80b481471f941296157983f89
7
+ data.tar.gz: 6ce0d5f2ec69c816ecb3df5bb658e01747ec000c7bc2c16280e0c42623510f45c55252330639e088dd4b28a1c93c89b283190ad3d31019cde22c1db83c3f26b4
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- iso-bib-item (0.4.3)
4
+ iso-bib-item (0.4.4)
5
5
  isoics (~> 0.1.6)
6
6
  nokogiri (~> 1.8.4)
7
7
  ruby_deep_clone (~> 0.8.0)
@@ -49,7 +49,7 @@ module IsoBibItem
49
49
  # @params date [String] 'yyyy' or 'yyyy-mm'
50
50
  def parse_date(date)
51
51
  return unless date
52
- if date =~ /\d{4}/
52
+ if date =~ /^\d{4}$/
53
53
  Time.strptime date, '%Y'
54
54
  else
55
55
  Time.strptime date, '%Y-%m'
@@ -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(type, description = [])
19
- @type = type
20
- @description = description.map { |d| FormattedString.new d }
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:, script:, type: 'plain')
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['format'] = type
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 ':' + pubdate&.first&.on&.year&.to_s
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
- @contributors.select do |c|
273
- c.role.select { |r| r.type == 'publisher' }.any?
274
- end
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
- # docidentifier.to_xml builder
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]
@@ -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 = 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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: false
2
2
 
3
3
  module IsoBibItem
4
- VERSION = '0.4.3'.freeze
4
+ VERSION = '0.4.4'.freeze
5
5
  end
@@ -49,8 +49,8 @@ module IsoBibItem
49
49
  end
50
50
 
51
51
  def fetch_titles(doc)
52
- doc.xpath('/bibitem/title').map do |t|
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('name').map do |n|
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('abbreviation')&.text,
103
- url: org.at('uri')&.text)
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 './name/completename'
108
- affilations = person.xpath('./affiliation').map do |a|
109
- org = a.at './organization'
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
- contacts = person.xpath('./contact').map do |c|
113
- if (addr = c.at './address')
114
- streets = addr.xpath('./street').map(&:text)
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: addr.at('./city').text,
118
- state: addr.at('./state').text,
119
- country: addr.at('./country').text,
120
- postcode: addr.at('./postcode').text
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 = c.child
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('/bibitem/contributor').map do |c|
137
- entity = if (org = c.at './organization') then get_org(org)
138
- elsif (person = c.at './person') then get_person(person)
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
- IsoBibItem::ContributionInfo.new entity: entity, role: [c.at('role')[:type]]
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('/bibitem/relation').map do |r|
190
- DocumentRelation.new(type: r[:type],
191
- identifier: r&.at('./bibitem/formattedref | ./bibitem/docidentifier')&.text)
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.3
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-19 00:00:00.000000000 Z
11
+ date: 2018-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler