relaton-bib 1.13.3 → 1.13.5

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: ca70214e52f3a00a9388de24a1e07fa6464e0cb23831fd14775ce0e29c929fdf
4
- data.tar.gz: 33cafac4c23e9dc57f102982bffbea20c25420f89471f164a0f875e4e6a74e26
3
+ metadata.gz: 0caab7f3d9965a4a482826d13169b71667104909e0e88b5da5e0f26e63ae2949
4
+ data.tar.gz: 07fb1078b43b5490685e9219569fa304a0c3f9024145aad4a1406eec103fcfd6
5
5
  SHA512:
6
- metadata.gz: d5eb2c4f5b7c13337a0e1f560d69ad140f91ea49405c3a4d876110bcdab32e532043a65187ca5fa6973c6cb0cf0240c285430a58d32338d186da882632194b2d
7
- data.tar.gz: 3fd3d4b199c1c190c4920c7daba0e73979a6e82ee24648a84ab3057e2cee08345db9cc929ba324773a55d0e1fe4160ca5af2320a2e297c52dfcbace78bbcd282
6
+ metadata.gz: afdba375985986ad6be85d4491f4477c69bf61c8adf998684d037d8100e4298cc8edb7734b311f0a9adeb3252da08b961e6499263a814b6edcbb92919ebc98b0
7
+ data.tar.gz: ea84abe94491d7f43e29aca0b5a7a2334876f419d653ca6f2f340c05d1a5ae0c3cbee226731969d4489179767362547e0d3ce4474143e670f35bdd7b5fc03981
@@ -145,7 +145,7 @@ module RelatonBib
145
145
  # @param language [Arra<String>]
146
146
  # @param script [Array<String>]
147
147
  # @param docstatus [RelatonBib::DocumentStatus, nil]
148
- # @param edition [RelatonBib::Edition, nil]
148
+ # @param edition [RelatonBib::Edition, String, Integer, Float, nil]
149
149
  # @param version [Array<RelatonBib::BibliographicItem::Version>]
150
150
  # @param biblionote [RelatonBib::BiblioNoteCollection]
151
151
  # @param series [Array<RelatonBib::Series>]
@@ -240,8 +240,9 @@ module RelatonBib
240
240
  @docnumber = args[:docnumber]
241
241
  @edition = case args[:edition]
242
242
  when Hash then Edition.new(**args[:edition])
243
- when String then Edition.new(content: args[:edition])
244
- else args[:edition]
243
+ when String, Integer, Float
244
+ Edition.new(content: args[:edition].to_s)
245
+ when Edition then args[:edition]
245
246
  end
246
247
  @version = args.fetch :version, []
247
248
  @biblionote = args.fetch :biblionote, BiblioNoteCollection.new([])
@@ -9,12 +9,12 @@ module RelatonBib
9
9
  #
10
10
  # Initialize edition.
11
11
  #
12
- # @param [String] content edition
13
- # @param [String, nil] number number
12
+ # @param [String, Integer, Float] content edition
13
+ # @param [String, Integer, Float, nil] number number
14
14
  #
15
15
  def initialize(content:, number: nil)
16
- @content = content
17
- @number = number
16
+ @content = content.to_s
17
+ @number = number&.to_s
18
18
  end
19
19
 
20
20
  #
@@ -31,6 +31,62 @@ module RelatonBib
31
31
  super
32
32
  end
33
33
 
34
+ #
35
+ # Encode content.
36
+ #
37
+ # @param [String] cnt content
38
+ #
39
+ # @return [String] encoded content
40
+ #
41
+ def encode(cnt) # rubocop:disable Metrics/MethodLength
42
+ return unless cnt
43
+ return escp(cnt) unless format == "text/html"
44
+
45
+ parts = cnt.scan(%r{
46
+ <(?<tago>\w+)(?<attrs>[^>]*)> | # tag open
47
+ </(?<tagc>\w+)> | # tag close
48
+ (?<cmt><!--.*?-->) | # comment
49
+ (?<cnt>.+?)(?=<|$) # content
50
+ }x)
51
+ scan_xml parts
52
+ end
53
+
54
+ #
55
+ # Scan XML and escape HTML entities.
56
+ #
57
+ # @param [Array<Array<String,nil>>] parts XML parts
58
+ #
59
+ # @return [String] output string
60
+ #
61
+ def scan_xml(parts) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/MethodLength
62
+ return "" unless parts.any?
63
+
64
+ out = ""
65
+ while parts.any? && (parts.first[3] || parts.first[4])
66
+ _, _, _, cmt, cnt = parts.shift
67
+ out += "#{cmt}#{escp(cnt)}"
68
+ end
69
+ unless out.empty?
70
+ out += scan_xml(parts) if parts.any? && parts.first[0]
71
+ return out
72
+ end
73
+
74
+ tago, attrs, tagc, = parts.shift
75
+ out = if tago && attrs && attrs[-1] == "/"
76
+ "<#{tago}#{attrs}>"
77
+ elsif tago
78
+ inr = scan_xml parts
79
+ _, _, tagc, = parts.shift
80
+ if tago == tagc
81
+ "<#{tago}#{attrs}>#{inr}</#{tagc}>"
82
+ else
83
+ "#{escp("<#{tago}#{attrs}>")}#{inr}#{escp("</#{tagc}>")}"
84
+ end
85
+ end
86
+ out += scan_xml(parts) if parts.any? && (parts.first[0] || parts.first[3] || parts.first[4])
87
+ out
88
+ end
89
+
34
90
  # @return [Hash]
35
91
  def to_hash
36
92
  hash = super
@@ -46,7 +102,7 @@ module RelatonBib
46
102
  # @return [String]
47
103
  def to_asciibib(prefix = "", count = 1, has_attrs = false)
48
104
  has_attrs ||= !(format.nil? || format.empty?)
49
- pref = prefix.empty? ? prefix : prefix + "."
105
+ pref = prefix.empty? ? prefix : "#{prefix}."
50
106
  # out = count > 1 ? "#{prefix}::\n" : ""
51
107
  out = super
52
108
  out += "#{pref}format:: #{format}\n" if format
@@ -76,51 +76,7 @@ module RelatonBib
76
76
  # @return [String] encoded content
77
77
  #
78
78
  def encode(cnt) # rubocop:disable Metrics/MethodLength
79
- return unless cnt
80
-
81
- parts = cnt.scan(%r{
82
- <(?<tago>\w+)(?<attrs>[^>]*)> | # tag open
83
- </(?<tagc>\w+)> | # tag close
84
- (?<cmt><!--.*?-->) | # comment
85
- (?<cnt>.+?)(?=<|$) # content
86
- }x)
87
- scan_xml parts
88
- end
89
-
90
- #
91
- # Scan XML and escape HTML entities.
92
- #
93
- # @param [Array<Array<String,nil>>] parts XML parts
94
- #
95
- # @return [String] output string
96
- #
97
- def scan_xml(parts) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity,Metrics/MethodLength
98
- return "" unless parts.any?
99
-
100
- out = ""
101
- while parts.any? && (parts.first[3] || parts.first[4])
102
- _, _, _, cmt, cnt = parts.shift
103
- out += "#{cmt}#{escp(cnt)}"
104
- end
105
- unless out.empty?
106
- out += scan_xml(parts) if parts.any? && parts.first[0]
107
- return out
108
- end
109
-
110
- tago, attrs, tagc, = parts.shift
111
- out = if tago && attrs && attrs[-1] == "/"
112
- "<#{tago}#{attrs}>"
113
- elsif tago
114
- inr = scan_xml parts
115
- _, _, tagc, = parts.shift
116
- if tago == tagc
117
- "<#{tago}#{attrs}>#{inr}</#{tagc}>"
118
- else
119
- "#{escp("<#{tago}#{attrs}>")}#{inr}#{escp("</#{tagc}>")}"
120
- end
121
- end
122
- out += scan_xml(parts) if parts.any? && (parts.first[0] || parts.first[3] || parts.first[4])
123
- out
79
+ escp cnt
124
80
  end
125
81
 
126
82
  #
@@ -1,3 +1,3 @@
1
1
  module RelatonBib
2
- VERSION = "1.13.3".freeze
2
+ VERSION = "1.13.5".freeze
3
3
  end
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.3
4
+ version: 1.13.5
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-15 00:00:00.000000000 Z
11
+ date: 2022-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug