fb2rb 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/release.yml +3 -9
- data/CHANGELOG.adoc +5 -0
- data/fb2rb.gemspec +3 -2
- data/lib/fb2rb.rb +111 -109
- data/lib/fb2rb/version.rb +1 -1
- metadata +20 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3232aa66bba2be36e9f72b67c198a6b2e1b8e13d2cb51746264b44daaab9c60e
|
4
|
+
data.tar.gz: 00c679822965363b7ffade747f1898f9d5a687c408cab6240afa8ac150108593
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7684b0249c15f2ca45fd209df32b6dae4f52192d0aa2cf17fff9c63c83666bbec7c1c7aafc5c4055e87a13f2967113056a81d94c5bc490448897a61f73695255
|
7
|
+
data.tar.gz: 9e93f45e0567bac65cdf97b9c18d2912b869d5a605d228e1bf667e58739a915a092d5623b6b385fe844817e337457444bca74580ebdb9bcd5720dcaef6af304a
|
@@ -13,12 +13,6 @@ jobs:
|
|
13
13
|
with:
|
14
14
|
ruby-version: 2.7
|
15
15
|
- name: Publish to RubyGems.org
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
chmod 0600 $HOME/.gem/credentials
|
20
|
-
printf -- "---\n:rubygems_api_key: ${RUBYGEMS_API_KEY}\n" > $HOME/.gem/credentials
|
21
|
-
gem build *.gemspec
|
22
|
-
gem push *.gem
|
23
|
-
env:
|
24
|
-
RUBYGEMS_API_KEY: ${{secrets.RUBYGEMS_API_KEY}}
|
16
|
+
uses: dawidd6/action-publish-gem@v1
|
17
|
+
with:
|
18
|
+
api_key: ${{ secrets.RUBYGEMS_API_KEY }}
|
data/CHANGELOG.adoc
CHANGED
@@ -7,6 +7,11 @@
|
|
7
7
|
This document provides a high-level view of the changes to the {project-name} by release.
|
8
8
|
For a detailed view of what has changed, refer to the {uri-project}/commits/master[commit history] on GitHub.
|
9
9
|
|
10
|
+
== 0.5.0 (2020-12-07) - @slonopotamus
|
11
|
+
|
12
|
+
* return `nil` from `FB2rb::Book.read_compressed` for empty ZIP files
|
13
|
+
* **breaking change**: switch to named parameters instead of optional
|
14
|
+
|
10
15
|
== 0.4.0 (2020-11-24) - @slonopotamus
|
11
16
|
|
12
17
|
* add `Book::add_stylesheet` method
|
data/fb2rb.gemspec
CHANGED
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
|
|
23
23
|
|
24
24
|
s.add_development_dependency 'rake', '~> 13.0.0'
|
25
25
|
s.add_development_dependency 'rspec', '~> 3.10.0'
|
26
|
-
s.add_development_dependency 'rubocop', '~>
|
27
|
-
s.add_development_dependency 'rubocop-
|
26
|
+
s.add_development_dependency 'rubocop', '~> 1.5.0'
|
27
|
+
s.add_development_dependency 'rubocop-rake', '~> 0.5.0'
|
28
|
+
s.add_development_dependency 'rubocop-rspec', '~> 2.0.0'
|
28
29
|
end
|
data/lib/fb2rb.rb
CHANGED
@@ -22,7 +22,7 @@ module FB2rb
|
|
22
22
|
# @return [Array<FB2fb::Binary>]
|
23
23
|
attr_accessor(:binaries)
|
24
24
|
|
25
|
-
def initialize(description
|
25
|
+
def initialize(description: Description.new, bodies: [], binaries: [], stylesheets: [])
|
26
26
|
@binaries = binaries
|
27
27
|
@bodies = bodies
|
28
28
|
@description = description
|
@@ -43,6 +43,7 @@ module FB2rb
|
|
43
43
|
return parse(xml, fb2_prefix, xlink_prefix)
|
44
44
|
end
|
45
45
|
end
|
46
|
+
nil
|
46
47
|
end
|
47
48
|
|
48
49
|
# Reads existing uncompressed FB2 file from an IO object, and creates new Book object.
|
@@ -64,16 +65,16 @@ module FB2rb
|
|
64
65
|
# @return [FB2rb::Book]
|
65
66
|
def parse(xml, fb2_prefix, xlink_prefix) # rubocop:disable Metrics/MethodLength
|
66
67
|
Book.new(
|
67
|
-
Description.parse(
|
68
|
+
description: Description.parse(
|
68
69
|
xml.xpath("/#{fb2_prefix}:FictionBook/#{fb2_prefix}:description"), fb2_prefix, xlink_prefix
|
69
70
|
),
|
70
|
-
xml.xpath("/#{fb2_prefix}:FictionBook/#{fb2_prefix}:body").map do |node|
|
71
|
+
bodies: xml.xpath("/#{fb2_prefix}:FictionBook/#{fb2_prefix}:body").map do |node|
|
71
72
|
Body.parse(node)
|
72
73
|
end,
|
73
|
-
xml.xpath("#{fb2_prefix}:FictionBook/#{fb2_prefix}:binary").map do |node|
|
74
|
+
binaries: xml.xpath("#{fb2_prefix}:FictionBook/#{fb2_prefix}:binary").map do |node|
|
74
75
|
Binary.parse(node)
|
75
76
|
end,
|
76
|
-
xml.xpath("/#{fb2_prefix}:FictionBook/#{fb2_prefix}:stylesheet").map do |node|
|
77
|
+
stylesheets: xml.xpath("/#{fb2_prefix}:FictionBook/#{fb2_prefix}:stylesheet").map do |node|
|
77
78
|
Stylesheet.parse(node)
|
78
79
|
end
|
79
80
|
)
|
@@ -106,12 +107,12 @@ module FB2rb
|
|
106
107
|
end
|
107
108
|
end
|
108
109
|
|
109
|
-
def add_binary(
|
110
|
+
def add_binary(id, filename_or_io, content_type = nil)
|
110
111
|
if filename_or_io.respond_to?(:read)
|
111
|
-
add_binary_io
|
112
|
+
add_binary_io id, filename_or_io, content_type
|
112
113
|
else
|
113
114
|
File.open(filename_or_io, 'r') do |io|
|
114
|
-
add_binary_io
|
115
|
+
add_binary_io id, io, content_type
|
115
116
|
end
|
116
117
|
end
|
117
118
|
end
|
@@ -169,17 +170,17 @@ module FB2rb
|
|
169
170
|
write_uncompressed(zos)
|
170
171
|
end
|
171
172
|
|
172
|
-
def add_binary_io(
|
173
|
+
def add_binary_io(id, io, content_type = nil)
|
173
174
|
io.binmode
|
174
175
|
content = io.read
|
175
|
-
@binaries << Binary.new(
|
176
|
+
@binaries << Binary.new(id: id, content: content, content_type: content_type)
|
176
177
|
self
|
177
178
|
end
|
178
179
|
|
179
180
|
def add_stylesheet_io(content_type, io)
|
180
181
|
io.binmode
|
181
182
|
content = io.read
|
182
|
-
@stylesheets << Stylesheet.new(content_type, content)
|
183
|
+
@stylesheets << Stylesheet.new(content_type: content_type, content: content)
|
183
184
|
self
|
184
185
|
end
|
185
186
|
end
|
@@ -196,13 +197,14 @@ module FB2rb
|
|
196
197
|
attr_accessor(:publish_info)
|
197
198
|
# @return [Array<FB2rb::CustomInfo>]
|
198
199
|
attr_accessor(:custom_infos)
|
200
|
+
|
199
201
|
# TODO: <output>
|
200
202
|
|
201
|
-
def initialize(title_info
|
202
|
-
document_info
|
203
|
-
publish_info
|
204
|
-
src_title_info
|
205
|
-
custom_infos
|
203
|
+
def initialize(title_info: TitleInfo.new,
|
204
|
+
document_info: DocumentInfo.new,
|
205
|
+
publish_info: nil,
|
206
|
+
src_title_info: nil,
|
207
|
+
custom_infos: [])
|
206
208
|
@title_info = title_info
|
207
209
|
@document_info = document_info
|
208
210
|
@publish_info = publish_info
|
@@ -215,11 +217,11 @@ module FB2rb
|
|
215
217
|
publish_info_xml = xml.at("./#{fb2_prefix}:publish-info")
|
216
218
|
src_title_info_xml = xml.at("./#{fb2_prefix}:src-title-info")
|
217
219
|
Description.new(
|
218
|
-
TitleInfo.parse(xml.at("./#{fb2_prefix}:title-info"), fb2_prefix, xlink_prefix),
|
219
|
-
DocumentInfo.parse(xml.at("./#{fb2_prefix}:document-info"), fb2_prefix),
|
220
|
-
publish_info_xml.nil? ? nil : PublishInfo.parse(publish_info_xml, fb2_prefix),
|
221
|
-
src_title_info_xml.nil? ? nil : TitleInfo.parse(src_title_info_xml, fb2_prefix, xlink_prefix),
|
222
|
-
xml.xpath("./#{fb2_prefix}:custom-info").map do |node|
|
220
|
+
title_info: TitleInfo.parse(xml.at("./#{fb2_prefix}:title-info"), fb2_prefix, xlink_prefix),
|
221
|
+
document_info: DocumentInfo.parse(xml.at("./#{fb2_prefix}:document-info"), fb2_prefix),
|
222
|
+
publish_info: publish_info_xml.nil? ? nil : PublishInfo.parse(publish_info_xml, fb2_prefix),
|
223
|
+
src_title_info: src_title_info_xml.nil? ? nil : TitleInfo.parse(src_title_info_xml, fb2_prefix, xlink_prefix),
|
224
|
+
custom_infos: xml.xpath("./#{fb2_prefix}:custom-info").map do |node|
|
223
225
|
CustomInfo.parse(node)
|
224
226
|
end
|
225
227
|
)
|
@@ -241,47 +243,47 @@ module FB2rb
|
|
241
243
|
# Holds <stylesheet> data
|
242
244
|
class Stylesheet
|
243
245
|
# @return [String]
|
244
|
-
attr_accessor(:
|
246
|
+
attr_accessor(:content_type)
|
245
247
|
# @return [String, nil]
|
246
248
|
attr_accessor(:content)
|
247
249
|
|
248
|
-
def initialize(
|
249
|
-
@
|
250
|
+
def initialize(content_type: '', content: nil)
|
251
|
+
@content_type = content_type
|
250
252
|
@content = content
|
251
253
|
end
|
252
254
|
|
253
255
|
def self.parse(xml)
|
254
|
-
Stylesheet.new(xml['type'], xml.text)
|
256
|
+
Stylesheet.new(content_type: xml['type'], content: xml.text)
|
255
257
|
end
|
256
258
|
|
257
259
|
def to_xml(xml)
|
258
260
|
return if @content.nil?
|
259
261
|
|
260
|
-
xml.send('stylesheet', @content, 'type' => @
|
262
|
+
xml.send('stylesheet', @content, 'type' => @content_type)
|
261
263
|
end
|
262
264
|
end
|
263
265
|
|
264
266
|
# Holds <custom-info> data
|
265
267
|
class CustomInfo
|
266
268
|
# @return [String]
|
267
|
-
attr_accessor(:
|
269
|
+
attr_accessor(:type)
|
268
270
|
# @return [String, nil]
|
269
271
|
attr_accessor(:content)
|
270
272
|
|
271
|
-
def initialize(
|
272
|
-
@
|
273
|
+
def initialize(type: '', content: nil)
|
274
|
+
@type = type
|
273
275
|
@content = content
|
274
276
|
end
|
275
277
|
|
276
278
|
# @return [FB2rb::CustomInfo]
|
277
279
|
def self.parse(xml)
|
278
|
-
CustomInfo.new(xml['info-type'], xml.text)
|
280
|
+
CustomInfo.new(type: xml['info-type'], content: xml.text)
|
279
281
|
end
|
280
282
|
|
281
283
|
def to_xml(xml)
|
282
284
|
return if @content.nil?
|
283
285
|
|
284
|
-
xml.send('custom-info', @content, 'info-type' => @
|
286
|
+
xml.send('custom-info', @content, 'info-type' => @type)
|
285
287
|
end
|
286
288
|
end
|
287
289
|
|
@@ -300,12 +302,12 @@ module FB2rb
|
|
300
302
|
# @return [Array<FB2RB::Sequence>]
|
301
303
|
attr_accessor(:sequences)
|
302
304
|
|
303
|
-
def initialize(book_name
|
304
|
-
publisher
|
305
|
-
city
|
306
|
-
year
|
307
|
-
isbn
|
308
|
-
sequences
|
305
|
+
def initialize(book_name: nil, # rubocop:disable Metrics/ParameterLists
|
306
|
+
publisher: nil,
|
307
|
+
city: nil,
|
308
|
+
year: nil,
|
309
|
+
isbn: nil,
|
310
|
+
sequences: [])
|
309
311
|
@book_name = book_name
|
310
312
|
@publisher = publisher
|
311
313
|
@city = city
|
@@ -317,12 +319,12 @@ module FB2rb
|
|
317
319
|
# @return [FB2RB::PublishInfo]
|
318
320
|
def self.parse(xml, fb2_prefix)
|
319
321
|
PublishInfo.new(
|
320
|
-
xml.at("./#{fb2_prefix}:book-name/text()")&.text,
|
321
|
-
xml.at("./#{fb2_prefix}:publisher/text()")&.text,
|
322
|
-
xml.at("./#{fb2_prefix}:city/text()")&.text,
|
323
|
-
xml.at("./#{fb2_prefix}:year/text()")&.text,
|
324
|
-
xml.at("./#{fb2_prefix}:isbn/text()")&.text,
|
325
|
-
xml.xpath("./#{fb2_prefix}:sequence").map do |node|
|
322
|
+
book_name: xml.at("./#{fb2_prefix}:book-name/text()")&.text,
|
323
|
+
publisher: xml.at("./#{fb2_prefix}:publisher/text()")&.text,
|
324
|
+
city: xml.at("./#{fb2_prefix}:city/text()")&.text,
|
325
|
+
year: xml.at("./#{fb2_prefix}:year/text()")&.text,
|
326
|
+
isbn: xml.at("./#{fb2_prefix}:isbn/text()")&.text,
|
327
|
+
sequences: xml.xpath("./#{fb2_prefix}:sequence").map do |node|
|
326
328
|
Sequence.parse(node)
|
327
329
|
end
|
328
330
|
)
|
@@ -363,15 +365,15 @@ module FB2rb
|
|
363
365
|
# @return [Array<String>]
|
364
366
|
attr_accessor(:publishers)
|
365
367
|
|
366
|
-
def initialize(authors
|
367
|
-
program_used
|
368
|
-
date
|
369
|
-
src_urls
|
370
|
-
src_ocr
|
371
|
-
id
|
372
|
-
version
|
373
|
-
history
|
374
|
-
publishers
|
368
|
+
def initialize(authors: [], # rubocop:disable Metrics/ParameterLists
|
369
|
+
program_used: nil,
|
370
|
+
date: FB2Date.new,
|
371
|
+
src_urls: [],
|
372
|
+
src_ocr: nil,
|
373
|
+
id: '',
|
374
|
+
version: '',
|
375
|
+
history: nil,
|
376
|
+
publishers: [])
|
375
377
|
@authors = authors
|
376
378
|
@program_used = program_used
|
377
379
|
@date = date
|
@@ -387,17 +389,17 @@ module FB2rb
|
|
387
389
|
def self.parse(xml, fb2_prefix) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
|
388
390
|
date = xml.at("./#{fb2_prefix}:date")
|
389
391
|
DocumentInfo.new(
|
390
|
-
xml.xpath("./#{fb2_prefix}:author").map do |node|
|
392
|
+
authors: xml.xpath("./#{fb2_prefix}:author").map do |node|
|
391
393
|
Author.parse(node, fb2_prefix)
|
392
394
|
end,
|
393
|
-
xml.at("./#{fb2_prefix}:program-used")&.text,
|
394
|
-
date.nil? ? FB2Date.new : FB2Date.parse(date),
|
395
|
-
xml.xpath("./#{fb2_prefix}:src-url").map(&:text),
|
396
|
-
xml.at("./#{fb2_prefix}:src-ocr")&.text,
|
397
|
-
xml.at("./#{fb2_prefix}:id").text,
|
398
|
-
xml.at("./#{fb2_prefix}:version")&.text,
|
399
|
-
xml.at("./#{fb2_prefix}:history")&.children&.to_s&.strip,
|
400
|
-
xml.xpath("./#{fb2_prefix}:publisher").map(&:text)
|
395
|
+
program_used: xml.at("./#{fb2_prefix}:program-used")&.text,
|
396
|
+
date: date.nil? ? FB2Date.new : FB2Date.parse(date),
|
397
|
+
src_urls: xml.xpath("./#{fb2_prefix}:src-url").map(&:text),
|
398
|
+
src_ocr: xml.at("./#{fb2_prefix}:src-ocr")&.text,
|
399
|
+
id: xml.at("./#{fb2_prefix}:id").text,
|
400
|
+
version: xml.at("./#{fb2_prefix}:version")&.text,
|
401
|
+
history: xml.at("./#{fb2_prefix}:history")&.children&.to_s&.strip,
|
402
|
+
publishers: xml.xpath("./#{fb2_prefix}:publisher").map(&:text)
|
401
403
|
)
|
402
404
|
end
|
403
405
|
|
@@ -451,17 +453,17 @@ module FB2rb
|
|
451
453
|
# @return [Array<FB2rb::Sequence>]
|
452
454
|
attr_accessor(:sequences)
|
453
455
|
|
454
|
-
def initialize(genres
|
455
|
-
authors
|
456
|
-
book_title
|
457
|
-
annotation
|
458
|
-
keywords
|
459
|
-
date
|
460
|
-
coverpage
|
461
|
-
lang
|
462
|
-
src_lang
|
463
|
-
translators
|
464
|
-
sequences
|
456
|
+
def initialize(genres: [], # rubocop:disable Metrics/MethodLength, Metrics/ParameterLists
|
457
|
+
authors: [],
|
458
|
+
book_title: '',
|
459
|
+
annotation: nil,
|
460
|
+
keywords: [],
|
461
|
+
date: nil,
|
462
|
+
coverpage: nil,
|
463
|
+
lang: 'en',
|
464
|
+
src_lang: nil,
|
465
|
+
translators: [],
|
466
|
+
sequences: [])
|
465
467
|
@genres = genres
|
466
468
|
@authors = authors
|
467
469
|
@book_title = book_title
|
@@ -480,21 +482,21 @@ module FB2rb
|
|
480
482
|
date = xml.at("./#{fb2_prefix}:date")
|
481
483
|
coverpage = xml.at("./#{fb2_prefix}:coverpage")
|
482
484
|
TitleInfo.new(
|
483
|
-
xml.xpath("./#{fb2_prefix}:genre/text()").map(&:text),
|
484
|
-
xml.xpath("./#{fb2_prefix}:author").map do |node|
|
485
|
+
genres: xml.xpath("./#{fb2_prefix}:genre/text()").map(&:text),
|
486
|
+
authors: xml.xpath("./#{fb2_prefix}:author").map do |node|
|
485
487
|
Author.parse(node, fb2_prefix)
|
486
488
|
end,
|
487
|
-
xml.at("./#{fb2_prefix}:book-title/text()")&.text,
|
488
|
-
xml.at("./#{fb2_prefix}:annotation")&.children.to_s.strip,
|
489
|
-
xml.at("./#{fb2_prefix}:keywords/text()")&.text&.split(', ') || [],
|
490
|
-
date.nil? ? nil : FB2Date.parse(date),
|
491
|
-
coverpage.nil? ? nil : Coverpage.parse(coverpage, fb2_prefix, xlink_prefix),
|
492
|
-
xml.at("./#{fb2_prefix}:lang/text()").text,
|
493
|
-
xml.at("./#{fb2_prefix}:src-lang/text()")&.text,
|
494
|
-
xml.xpath("./#{fb2_prefix}:translator").map do |node|
|
489
|
+
book_title: xml.at("./#{fb2_prefix}:book-title/text()")&.text,
|
490
|
+
annotation: xml.at("./#{fb2_prefix}:annotation")&.children.to_s.strip,
|
491
|
+
keywords: xml.at("./#{fb2_prefix}:keywords/text()")&.text&.split(', ') || [],
|
492
|
+
date: date.nil? ? nil : FB2Date.parse(date),
|
493
|
+
coverpage: coverpage.nil? ? nil : Coverpage.parse(coverpage, fb2_prefix, xlink_prefix),
|
494
|
+
lang: xml.at("./#{fb2_prefix}:lang/text()").text,
|
495
|
+
src_lang: xml.at("./#{fb2_prefix}:src-lang/text()")&.text,
|
496
|
+
translators: xml.xpath("./#{fb2_prefix}:translator").map do |node|
|
495
497
|
Author.parse(node, fb2_prefix)
|
496
498
|
end,
|
497
|
-
xml.xpath("./#{fb2_prefix}:sequence").map do |node|
|
499
|
+
sequences: xml.xpath("./#{fb2_prefix}:sequence").map do |node|
|
498
500
|
Sequence.parse(node)
|
499
501
|
end
|
500
502
|
)
|
@@ -534,13 +536,13 @@ module FB2rb
|
|
534
536
|
# @return [Array<String>]
|
535
537
|
attr_accessor(:images)
|
536
538
|
|
537
|
-
def initialize(images
|
539
|
+
def initialize(images: [])
|
538
540
|
@images = images
|
539
541
|
end
|
540
542
|
|
541
543
|
def self.parse(xml, fb2_prefix, xlink_prefix)
|
542
544
|
Coverpage.new(
|
543
|
-
xml.xpath("./#{fb2_prefix}:image/@#{xlink_prefix}:href").map(&:to_s)
|
545
|
+
images: xml.xpath("./#{fb2_prefix}:image/@#{xlink_prefix}:href").map(&:to_s)
|
544
546
|
)
|
545
547
|
end
|
546
548
|
|
@@ -560,7 +562,7 @@ module FB2rb
|
|
560
562
|
# @return [Date, nil]
|
561
563
|
attr_accessor(:value)
|
562
564
|
|
563
|
-
def initialize(display_value
|
565
|
+
def initialize(display_value: '', value: nil)
|
564
566
|
@display_value = display_value
|
565
567
|
@value = value
|
566
568
|
end
|
@@ -568,8 +570,8 @@ module FB2rb
|
|
568
570
|
def self.parse(xml)
|
569
571
|
value = xml['value']
|
570
572
|
FB2Date.new(
|
571
|
-
xml.at('./text()')&.text || '',
|
572
|
-
value.nil? ? nil : Date.parse(value)
|
573
|
+
display_value: xml.at('./text()')&.text || '',
|
574
|
+
value: value.nil? ? nil : Date.parse(value)
|
573
575
|
)
|
574
576
|
end
|
575
577
|
|
@@ -587,14 +589,14 @@ module FB2rb
|
|
587
589
|
# @return [Integer, nil]
|
588
590
|
attr_accessor(:number)
|
589
591
|
|
590
|
-
def initialize(name
|
592
|
+
def initialize(name: '', number: nil)
|
591
593
|
@name = name
|
592
594
|
@number = number
|
593
595
|
end
|
594
596
|
|
595
597
|
# @return [FB2rb::Sequence]
|
596
598
|
def self.parse(xml)
|
597
|
-
Sequence.new(xml['name'], xml['number']&.to_i)
|
599
|
+
Sequence.new(name: xml['name'], number: xml['number']&.to_i)
|
598
600
|
end
|
599
601
|
|
600
602
|
def to_xml(xml)
|
@@ -621,13 +623,13 @@ module FB2rb
|
|
621
623
|
# @return [String, nil]
|
622
624
|
attr_accessor(:id)
|
623
625
|
|
624
|
-
def initialize(first_name
|
625
|
-
middle_name
|
626
|
-
last_name
|
627
|
-
nickname
|
628
|
-
home_pages
|
629
|
-
emails
|
630
|
-
id
|
626
|
+
def initialize(first_name: nil, # rubocop:disable Metrics/ParameterLists
|
627
|
+
middle_name: nil,
|
628
|
+
last_name: nil,
|
629
|
+
nickname: nil,
|
630
|
+
home_pages: [],
|
631
|
+
emails: [],
|
632
|
+
id: nil)
|
631
633
|
@first_name = first_name
|
632
634
|
@middle_name = middle_name
|
633
635
|
@last_name = last_name
|
@@ -640,13 +642,13 @@ module FB2rb
|
|
640
642
|
# @return [FB2rb::Author]
|
641
643
|
def self.parse(xml, fb2_prefix) # rubocop:disable Metrics/CyclomaticComplexity
|
642
644
|
Author.new(
|
643
|
-
xml.at("./#{fb2_prefix}:first-name/text()")&.text,
|
644
|
-
xml.at("./#{fb2_prefix}:middle-name/text()")&.text,
|
645
|
-
xml.at("./#{fb2_prefix}:last-name/text()")&.text,
|
646
|
-
xml.at("./#{fb2_prefix}:nickname/text()")&.text,
|
647
|
-
xml.xpath("./#{fb2_prefix}:home-page/text()").map(&:text),
|
648
|
-
xml.xpath("./#{fb2_prefix}:email/text()").map(&:text),
|
649
|
-
xml.at("./#{fb2_prefix}:id/text()")&.text
|
645
|
+
first_name: xml.at("./#{fb2_prefix}:first-name/text()")&.text,
|
646
|
+
middle_name: xml.at("./#{fb2_prefix}:middle-name/text()")&.text,
|
647
|
+
last_name: xml.at("./#{fb2_prefix}:last-name/text()")&.text,
|
648
|
+
nickname: xml.at("./#{fb2_prefix}:nickname/text()")&.text,
|
649
|
+
home_pages: xml.xpath("./#{fb2_prefix}:home-page/text()").map(&:text),
|
650
|
+
emails: xml.xpath("./#{fb2_prefix}:email/text()").map(&:text),
|
651
|
+
id: xml.at("./#{fb2_prefix}:id/text()")&.text
|
650
652
|
)
|
651
653
|
end
|
652
654
|
|
@@ -674,7 +676,7 @@ module FB2rb
|
|
674
676
|
# @return [String]
|
675
677
|
attr_accessor(:content)
|
676
678
|
|
677
|
-
def initialize(name
|
679
|
+
def initialize(name: nil, content: '')
|
678
680
|
@name = name
|
679
681
|
@content = content
|
680
682
|
end
|
@@ -682,8 +684,8 @@ module FB2rb
|
|
682
684
|
# @return [FB2rb::Body]
|
683
685
|
def self.parse(xml)
|
684
686
|
Body.new(
|
685
|
-
xml['name'],
|
686
|
-
xml.children.to_s.strip
|
687
|
+
name: xml['name'],
|
688
|
+
content: xml.children.to_s.strip
|
687
689
|
)
|
688
690
|
end
|
689
691
|
|
@@ -706,7 +708,7 @@ module FB2rb
|
|
706
708
|
# @return [String, nil]
|
707
709
|
attr_accessor(:content_type)
|
708
710
|
|
709
|
-
def initialize(id, content, content_type
|
711
|
+
def initialize(id: nil, content: ''.b, content_type: nil)
|
710
712
|
@id = id
|
711
713
|
@content = content
|
712
714
|
@content_type = content_type
|
@@ -714,7 +716,7 @@ module FB2rb
|
|
714
716
|
|
715
717
|
def self.parse(xml)
|
716
718
|
decoded = Base64.decode64(xml.text)
|
717
|
-
Binary.new(xml['id'], decoded, xml['content-type'])
|
719
|
+
Binary.new(id: xml['id'], content: decoded, content_type: xml['content-type'])
|
718
720
|
end
|
719
721
|
|
720
722
|
def to_xml(xml)
|
data/lib/fb2rb/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fb2rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marat Radchenko
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -72,28 +72,42 @@ dependencies:
|
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 1.5.0
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version:
|
82
|
+
version: 1.5.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop-rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.5.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.5.0
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: rubocop-rspec
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
86
100
|
requirements:
|
87
101
|
- - "~>"
|
88
102
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
103
|
+
version: 2.0.0
|
90
104
|
type: :development
|
91
105
|
prerelease: false
|
92
106
|
version_requirements: !ruby/object:Gem::Requirement
|
93
107
|
requirements:
|
94
108
|
- - "~>"
|
95
109
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
110
|
+
version: 2.0.0
|
97
111
|
description:
|
98
112
|
email:
|
99
113
|
- marat@slonopotamus.org
|