relaton-bib 1.13.8 → 1.13.9

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: 566350d7e96478f76484698d7b249e2fc7e22a454a3b2e9572d23b4ddac14723
4
- data.tar.gz: 53be5f2b3ee6967f22e654aae40133cbdba560ad176bbfc4c8c0f5cee541385c
3
+ metadata.gz: 50d370dad5e6a20ef5eaaed6633e0d62d80c0087f8a24d205dcb02723c025b35
4
+ data.tar.gz: 7ef8d3f6530096ed1e15bc66f148a3972490e39ba3c51bfc894a31cab8195d4f
5
5
  SHA512:
6
- metadata.gz: 0fbbf49b3d1cb2cd5a4e1b423f547cf03d4a9d2c8d9178b15e4089d384e8c42f15de338f9a8991c1cd9fd83e9a2ac1c1783b11b7d1f7fbd30d8b53e7652db077
7
- data.tar.gz: 011acbf178b30a5b62f9180f229e49ee4c804e75cba490df2802bad897261a6fed9e1d3a40c6cbd78554375de7884c1447afbdc02e48570976f439244edbaedd
6
+ metadata.gz: 305a89bc3529accd1087f9e7928172bacf6acb4672fa0215ee1b27406cca08cda484470227625c94928f5be4ac0766cd0b13b43059c0328b3f9d0ba03f6ad0af
7
+ data.tar.gz: 44e3711a83e329cba17baabbaacecc03736eef8c20857aac71c760bcfd7289071b1d2a60b70d0d9710d132c02c0607c0ad234522ee280b6867f1bf7fba69bed1
data/README.adoc CHANGED
@@ -103,7 +103,7 @@ item.to_xml
103
103
  </bibitem>"
104
104
  ----
105
105
 
106
- Default root element is `bibitem`. With argument `bibdata: true` the XML wrapped with `bibdata` element.
106
+ The default root element is `bibitem`. With argument `bibdata: true` the XML wrapped with `bibdata` element.
107
107
 
108
108
  [source,ruby]
109
109
  ----
@@ -117,7 +117,7 @@ item.to_xml bibdata: true
117
117
 
118
118
  ==== Date format
119
119
 
120
- By default date elements are formatted as year (yyyy). Option `:date_format` allows to output date elements in `:short` (yyyy-mm) and `:full` (yyyy-mm-dd) additiona formats.
120
+ By default date elements are formatted as a year (yyyy). Option `:date_format` allows to output date elements in `:short` (yyyy-mm) and `:full` (yyyy-mm-dd) additional formats.
121
121
 
122
122
  [source,ruby]
123
123
  ----
@@ -249,7 +249,7 @@ id:: ISOTC211
249
249
  fetched:: 2020-08-19
250
250
  title::
251
251
  title.type:: title-main
252
- title.conten:: Geographic information
252
+ title.content:: Geographic information
253
253
  title.format:: text/plain
254
254
  ...
255
255
  ----
data/grammars/biblio.rng CHANGED
@@ -854,6 +854,12 @@
854
854
  <optional>
855
855
  <attribute name="type"/>
856
856
  </optional>
857
+ <optional>
858
+ <attribute name="language"/>
859
+ </optional>
860
+ <optional>
861
+ <attribute name="script"/>
862
+ </optional>
857
863
  <data type="anyURI"/>
858
864
  </define>
859
865
  <define name="DateType">
@@ -882,6 +888,7 @@
882
888
  <value>vote-started</value>
883
889
  <value>vote-ended</value>
884
890
  <value>announced</value>
891
+ <value>stable-until</value>
885
892
  </choice>
886
893
  </define>
887
894
  <define name="bdate">
@@ -224,6 +224,13 @@ module RelatonBib
224
224
  end.compact
225
225
  end
226
226
 
227
+ #
228
+ # Parse organization from author element
229
+ #
230
+ # @param [Nokogiri::XML::Element] contrib author element
231
+ #
232
+ # @return [Hash] contribution info
233
+ #
227
234
  def full_name_org(contrib)
228
235
  return unless FULLNAMEORG.include? contrib[:fullname]
229
236
 
@@ -21,8 +21,8 @@ module RelatonBib
21
21
  # raise ArgumentError, %{Format "#{format}" is invalid.}
22
22
  # end
23
23
 
24
- super(content, language, script)
25
24
  @format = format
25
+ super(content, language, script)
26
26
  end
27
27
 
28
28
  # @param builder [Nokogiri::XML::Builder]
@@ -107,5 +107,22 @@ module RelatonBib
107
107
  out += "#{pref}format:: #{format}\n" if format
108
108
  out
109
109
  end
110
+
111
+ #
112
+ # Remove HTML tags except <em>, <strong>, <stem>, <sup>, <sub>, <tt>, <br>, <p>.
113
+ # Replace <i> with <em>, <b> with <strong>.
114
+ #
115
+ # @param [String] str content
116
+ #
117
+ # @return [String] cleaned content
118
+ #
119
+ def cleanup(str)
120
+ return str unless format == "text/html"
121
+
122
+ str.gsub(/<i>/, "<em>").gsub(/<\/i>/, "</em>")
123
+ .gsub(/<b>/, "<strong>").gsub(/<\/b>/, "</strong>")
124
+ .gsub(/<(?!\/?(em|strong|stem|sup|sub|tt|br\s?\/|p))[^\s!]\/?.*?>/, "")
125
+ # .gsub(/<\w+\s.+?>/, "")
126
+ end
110
127
  end
111
128
  end
@@ -33,7 +33,7 @@ module RelatonBib
33
33
  else c
34
34
  end
35
35
  end
36
- else content
36
+ else cleanup content
37
37
  end
38
38
  end
39
39
 
@@ -127,5 +127,16 @@ module RelatonBib
127
127
  else count > 1 ? "#{prefix}::\n" : ""
128
128
  end
129
129
  end
130
+
131
+ #
132
+ # Should be implemented in subclass.
133
+ #
134
+ # @param [String] str content
135
+ #
136
+ # @return [String] cleaned content
137
+ #
138
+ def cleanup(str)
139
+ str
140
+ end
130
141
  end
131
142
  end
@@ -3,15 +3,19 @@ require "addressable"
3
3
  module RelatonBib
4
4
  # Typed URI
5
5
  class TypedUri
6
- # @return [Symbol] :src/:obp/:rss
7
- attr_reader :type
6
+ # @return [String, nil]
7
+ attr_reader :type, :language, :script
8
8
  # @retutn [Addressable::URI]
9
9
  attr_reader :content
10
10
 
11
- # @param type [String, NilClass] src/obp/rss
12
- # @param content [String]
13
- def initialize(content:, type: nil)
11
+ # @param content [String] URL
12
+ # @param type [String, nil] src/obp/rss
13
+ # @param language [String, nil] language code Iso639 (optional) (default: nil)
14
+ # @param script [String, nil] script code Iso15924 (optional) (default: nil)
15
+ def initialize(content:, type: nil, language: nil, script: nil)
14
16
  @type = type
17
+ @language = language
18
+ @script = script
15
19
  @content = Addressable::URI.parse content if content
16
20
  end
17
21
 
@@ -24,12 +28,16 @@ module RelatonBib
24
28
  def to_xml(builder)
25
29
  doc = builder.uri content.to_s
26
30
  doc[:type] = type if type
31
+ doc[:language] = language if language
32
+ doc[:script] = script if script
27
33
  end
28
34
 
29
35
  # @return [Hash]
30
36
  def to_hash
31
37
  hash = { "content" => content.to_s }
32
38
  hash["type"] = type.to_s if type
39
+ hash["language"] = language if language
40
+ hash["script"] = script if script
33
41
  hash
34
42
  end
35
43
 
@@ -41,6 +49,8 @@ module RelatonBib
41
49
  out = count > 1 ? "#{pref}::\n" : ""
42
50
  out += "#{pref}.type:: #{type}\n" if type
43
51
  out += "#{pref}.content:: #{content}\n"
52
+ out += "#{pref}.language:: #{language}\n" if language
53
+ out += "#{pref}.script:: #{script}\n" if script
44
54
  out
45
55
  end
46
56
  end
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "1.13.8".freeze
2
+ VERSION = "1.13.9".freeze
3
3
  end
@@ -10,7 +10,7 @@ module RelatonBib
10
10
  if bibitem
11
11
  bib_item item_data(bibitem)
12
12
  else
13
- warn "[relaton-bib] WARNING: can't find bibitem or bibdata element "\
13
+ warn "[relaton-bib] WARNING: can't find bibitem or bibdata element " \
14
14
  "in the XML"
15
15
  end
16
16
  end
@@ -23,8 +23,8 @@ module RelatonBib
23
23
  def item_data(bibitem) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
24
24
  ext = bibitem.at "//ext"
25
25
  {
26
- id: bibitem[:id]&.empty? ? nil : bibitem[:id],
27
- type: bibitem[:type]&.empty? ? nil : bibitem[:type],
26
+ id: bibitem[:id].nil? || bibitem[:id].empty? ? nil : bibitem[:id],
27
+ type: bibitem[:type].nil? || bibitem[:type].empty? ? nil : bibitem[:type],
28
28
  fetched: bibitem.at("./fetched")&.text,
29
29
  title: fetch_titles(bibitem),
30
30
  formattedref: fref(bibitem),
@@ -141,7 +141,7 @@ module RelatonBib
141
141
  organization: sr.at("organization")&.text,
142
142
  abbreviation: abbreviation, from: sr.at("from")&.text,
143
143
  to: sr.at("to")&.text, number: sr.at("number")&.text,
144
- partnumber: sr.at("partnumber")&.text, run: sr.at("run")&.text,
144
+ partnumber: sr.at("partnumber")&.text, run: sr.at("run")&.text
145
145
  )
146
146
  end
147
147
  end
@@ -160,9 +160,6 @@ module RelatonBib
160
160
  def fetch_extent(item)
161
161
  item.xpath("./extent").reduce([]) do |a, ex|
162
162
  a + localities(ex)
163
- # Locality.new(
164
- # ex[:type], ex.at("referenceFrom")&.text, ex.at("referenceTo")&.text
165
- # )
166
163
  end
167
164
  end
168
165
 
@@ -401,7 +398,8 @@ module RelatonBib
401
398
  # @return [Arra<RelatonBib::TypedUri>]
402
399
  def fetch_link(item)
403
400
  item.xpath("./uri").map do |l|
404
- TypedUri.new type: l[:type], content: l.text
401
+ TypedUri.new(type: l[:type], content: l.text, language: l[:language],
402
+ script: l[:script])
405
403
  end
406
404
  end
407
405
 
@@ -412,7 +410,7 @@ module RelatonBib
412
410
  def fetch_relations(item, klass = DocumentRelation)
413
411
  item.xpath("./relation").map do |rel|
414
412
  klass.new(
415
- type: rel[:type]&.empty? ? nil : rel[:type],
413
+ type: rel[:type].nil? || rel[:type].empty? ? nil : rel[:type],
416
414
  description: relation_description(rel),
417
415
  bibitem: bib_item(item_data(rel.at("./bibitem"))),
418
416
  locality: localities(rel),
@@ -453,7 +451,7 @@ module RelatonBib
453
451
  # Create Locality object from Nokogiri::XML::Element
454
452
  #
455
453
  # @param loc [Nokogiri::XML::Element]
456
- # @param klass [RelatonBib::Locality.class, RelatonBib::LocalityStack.class]
454
+ # @param klass [RelatonBib::Locality, RelatonBib::LocalityStack]
457
455
  #
458
456
  # @return [RelatonBib::Locality]
459
457
  def locality(loc, klass = Locality)
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.13.8
4
+ version: 1.13.9
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-09-21 00:00:00.000000000 Z
11
+ date: 2022-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug