relaton-bib 1.13.7 → 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: 493716815449edfed921ea2239b0c066b614211c2722f261bf4f59d5aa094e54
4
- data.tar.gz: 661ad28bf88fcb3e5b27888885696c14385fbb9bfc891f4b20ea91d7e6dba1f1
3
+ metadata.gz: 50d370dad5e6a20ef5eaaed6633e0d62d80c0087f8a24d205dcb02723c025b35
4
+ data.tar.gz: 7ef8d3f6530096ed1e15bc66f148a3972490e39ba3c51bfc894a31cab8195d4f
5
5
  SHA512:
6
- metadata.gz: 2e5ef5a5bd17eafad776a09434fb8e7df82ec2ca3b4fc1e59a6e7d722a72e1c1f57ec75a80dfb1c651a7cea71160c04fb1083517169a68ba341bc3f607c8219c
7
- data.tar.gz: 7b556666124417d87dc58709325b4be7970fb4af443686e332376b739edaa8ad0041e0a26145954577a2b1f8674b078a31405ac2447868caa8df06b3eb25158c
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
@@ -101,6 +101,7 @@ module RelatonBib
101
101
  # @param content [String]
102
102
  # @param language [String]
103
103
  # @param script [String]
104
+ # @param format [String]
104
105
  def initialize(**args) # rubocop:disable Metrics/MethodLength
105
106
  unless args[:title] || args[:content]
106
107
  raise ArgumentError, %{Keyword "title" or "content" should be passed.}
@@ -108,24 +109,35 @@ module RelatonBib
108
109
 
109
110
  @type = args[:type]
110
111
 
111
- if args[:title]
112
- @title = args[:title]
112
+ case args[:title]
113
+ when FormattedString then @title = args[:title]
114
+ when Hash then @title = FormattedString.new(**args[:title])
113
115
  else
114
116
  fsargs = args.select { |k, _v| ARGS.include? k }
115
117
  @title = FormattedString.new(**fsargs)
116
118
  end
117
119
  end
118
120
 
119
- # @param title [String]
120
- # @return [TypedTitleStringCollection]
121
- def self.from_string(title, lang = nil, script = nil)
121
+ #
122
+ # Create TypedTitleStringCollection from string
123
+ #
124
+ # @param title [String] title string
125
+ # @param lang [String, nil] language code Iso639
126
+ # @param script [String, nil] script code Iso15924
127
+ # @param format [String] format text/html, text/plain
128
+ #
129
+ # @return [TypedTitleStringCollection] collection of TypedTitleString
130
+ #
131
+ def self.from_string(title, lang = nil, script = nil, format = "text/plain")
122
132
  types = %w[title-intro title-main title-part]
123
133
  ttls = split_title(title)
124
134
  tts = ttls.map.with_index do |p, i|
125
- new type: types[i], content: p, language: lang, script: script if p
135
+ next unless p
136
+
137
+ new type: types[i], content: p, language: lang, script: script, format: format
126
138
  end.compact
127
139
  tts << new(type: "main", content: ttls.compact.join(" - "),
128
- language: lang, script: script)
140
+ language: lang, script: script, format: format)
129
141
  TypedTitleStringCollection.new tts
130
142
  end
131
143
 
@@ -140,10 +152,10 @@ module RelatonBib
140
152
  end
141
153
 
142
154
  # @param ttls [Array<String>]
143
- # @return [Array<Strin, nil>]
155
+ # @return [Array<String, nil>]
144
156
  def self.intro_or_part(ttls)
145
157
  if /^(Part|Partie) \d+:/.match? ttls[1]
146
- [nil, ttls[0], ttls[1..-1].join(" -- ")]
158
+ [nil, ttls[0], ttls[1..].join(" -- ")]
147
159
  else
148
160
  parts = ttls.slice(2..-1)
149
161
  part = parts.join " -- " if parts.any?
@@ -162,13 +174,6 @@ module RelatonBib
162
174
  th = title.to_hash
163
175
  return th unless type
164
176
 
165
- # hash = { "type" => type }
166
- # if th.is_a? String
167
- # hash["content"] = th
168
- # else
169
- # hash.merge! th
170
- # end
171
- # hash
172
177
  th.merge "type" => type
173
178
  end
174
179
 
@@ -176,7 +181,7 @@ module RelatonBib
176
181
  # @param count [Integer] number of titles
177
182
  # @return [String]
178
183
  def to_asciibib(prefix = "", count = 1) # rubocop:disable Metrics/AbcSize
179
- pref = prefix.empty? ? prefix : prefix + "."
184
+ pref = prefix.empty? ? prefix : "#{prefix}."
180
185
  out = count > 1 ? "#{pref}title::\n" : ""
181
186
  out += "#{pref}title.type:: #{type}\n" if type
182
187
  out += title.to_asciibib "#{pref}title", 1, !(type.nil? || type.empty?)
@@ -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.7".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.7
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-20 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