fb2rb 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.adoc +5 -0
- data/lib/fb2rb.rb +75 -4
- data/lib/fb2rb/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1f9023970c90759eb32f56a5bbef46864bb5b6bbe74801b63d74b215bc20741
|
4
|
+
data.tar.gz: a44854f8a96a67c36a3bc7e3f66a24209de49d211508f267ccf6fe7f1fcf1651
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '062709548a3e5d5fd83ec9b85709f5beb5018d5d5b490dcc6f81af71c09d7e9a7d0c5bcd7b14fb1cff55491cda656987b55518f11c299f222918eba58d406ec4'
|
7
|
+
data.tar.gz: 45c0b3159351d8636695df9ec95a55b62ba7810af3b8320ed1210ea0895fd53a6cf35433bb803878133597f4f839c242efa9731004521c953475d0d56c1a8b13
|
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.1.1 (2020-07-23) - @slonopotamus
|
11
|
+
|
12
|
+
* Annonate field types
|
13
|
+
* Fix serialization of `<publisher>` in `<document-info>`
|
14
|
+
|
10
15
|
== 0.1.0 (2020-07-23) - @slonopotamus
|
11
16
|
|
12
17
|
* Initial release
|
data/lib/fb2rb.rb
CHANGED
@@ -13,9 +13,13 @@ module FB2rb
|
|
13
13
|
|
14
14
|
# Holds data of a single FB2 file
|
15
15
|
class Book
|
16
|
+
# @return [Array<FB2rb::Stylesheet>]
|
16
17
|
attr_accessor(:stylesheets)
|
18
|
+
# @return [FB2rb::Description]
|
17
19
|
attr_accessor(:description)
|
20
|
+
# @return [Array<FB2rb::Body>]
|
18
21
|
attr_accessor(:bodies)
|
22
|
+
# @return [Array<FB2fb::Binary>]
|
19
23
|
attr_accessor(:binaries)
|
20
24
|
|
21
25
|
def initialize(description = Description.new, bodies = [], binaries = [], stylesheets = [])
|
@@ -26,6 +30,7 @@ module FB2rb
|
|
26
30
|
end
|
27
31
|
|
28
32
|
# Reads existing FB2 file from an IO object, and creates new Book object.
|
33
|
+
# @return [FB2rb::Book]
|
29
34
|
def self.read(filename_or_io)
|
30
35
|
Zip::InputStream.open(filename_or_io) do |zis|
|
31
36
|
while (entry = zis.get_next_entry)
|
@@ -44,6 +49,7 @@ module FB2rb
|
|
44
49
|
prefix.nil? ? nil : prefix.sub(/^xmlns:/, '')
|
45
50
|
end
|
46
51
|
|
52
|
+
# @return [FB2rb::Book]
|
47
53
|
def self.parse(xml, fb2_prefix, xlink_prefix) # rubocop:disable Metrics/MethodLength
|
48
54
|
Book.new(
|
49
55
|
Description.parse(xml.xpath("/#{fb2_prefix}:FictionBook/#{fb2_prefix}:description"), fb2_prefix, xlink_prefix),
|
@@ -86,6 +92,7 @@ module FB2rb
|
|
86
92
|
end
|
87
93
|
|
88
94
|
# Serializes and returns FB2 as StringIO.
|
95
|
+
# @return [StringIO]
|
89
96
|
def to_ios
|
90
97
|
Zip::OutputStream.write_buffer do |io|
|
91
98
|
write_to_stream(io)
|
@@ -132,10 +139,15 @@ module FB2rb
|
|
132
139
|
|
133
140
|
# Holds <description> data
|
134
141
|
class Description
|
142
|
+
# @return [FB2rb::TitleInfo]
|
135
143
|
attr_accessor(:title_info)
|
144
|
+
# @return [FB2rb::TitleInfo, nil]
|
136
145
|
attr_accessor(:src_title_info)
|
146
|
+
# @return [FB2rb::DocumentInfo]
|
137
147
|
attr_accessor(:document_info)
|
148
|
+
# @return [FB2rb::PublishInfo, nil]
|
138
149
|
attr_accessor(:publish_info)
|
150
|
+
# @return [Array<FB2rb::CustomInfo>]
|
139
151
|
attr_accessor(:custom_infos)
|
140
152
|
# TODO: <output>
|
141
153
|
|
@@ -151,6 +163,7 @@ module FB2rb
|
|
151
163
|
@custom_infos = custom_infos
|
152
164
|
end
|
153
165
|
|
166
|
+
# @return [FB2rb::Description]
|
154
167
|
def self.parse(xml, fb2_prefix, xlink_prefix) # rubocop:disable Metrics/MethodLength
|
155
168
|
publish_info_xml = xml.at("./#{fb2_prefix}:publish-info")
|
156
169
|
src_title_info_xml = xml.at("./#{fb2_prefix}:src-title-info")
|
@@ -180,7 +193,9 @@ module FB2rb
|
|
180
193
|
|
181
194
|
# Holds <stylesheet> data
|
182
195
|
class Stylesheet
|
196
|
+
# @return [String]
|
183
197
|
attr_accessor(:type)
|
198
|
+
# @return [String, nil]
|
184
199
|
attr_accessor(:content)
|
185
200
|
|
186
201
|
def initialize(type = '', content = nil)
|
@@ -201,7 +216,9 @@ module FB2rb
|
|
201
216
|
|
202
217
|
# Holds <custom-info> data
|
203
218
|
class CustomInfo
|
219
|
+
# @return [String]
|
204
220
|
attr_accessor(:info_type)
|
221
|
+
# @return [String, nil]
|
205
222
|
attr_accessor(:content)
|
206
223
|
|
207
224
|
def initialize(info_type = '', content = nil)
|
@@ -209,6 +226,7 @@ module FB2rb
|
|
209
226
|
@content = content
|
210
227
|
end
|
211
228
|
|
229
|
+
# @return [FB2rb::CustomInfo]
|
212
230
|
def self.parse(xml)
|
213
231
|
CustomInfo.new(xml['info-type'], xml.text)
|
214
232
|
end
|
@@ -222,11 +240,17 @@ module FB2rb
|
|
222
240
|
|
223
241
|
# Holds <publish-info> data
|
224
242
|
class PublishInfo
|
243
|
+
# @return [String, nil]
|
225
244
|
attr_accessor(:book_name)
|
245
|
+
# @return [String, nil]
|
226
246
|
attr_accessor(:publisher)
|
247
|
+
# @return [String, nil]
|
227
248
|
attr_accessor(:city)
|
249
|
+
# @return [String, nil]
|
228
250
|
attr_accessor(:year)
|
251
|
+
# @return [String, nil]
|
229
252
|
attr_accessor(:isbn)
|
253
|
+
# @return [Array<FB2RB::Sequence>]
|
230
254
|
attr_accessor(:sequences)
|
231
255
|
|
232
256
|
def initialize(book_name = nil, # rubocop:disable Metrics/ParameterLists
|
@@ -243,6 +267,7 @@ module FB2rb
|
|
243
267
|
@sequences = sequences
|
244
268
|
end
|
245
269
|
|
270
|
+
# @return [FB2RB::PublishInfo]
|
246
271
|
def self.parse(xml, fb2_prefix)
|
247
272
|
PublishInfo.new(
|
248
273
|
xml.at("./#{fb2_prefix}:book-name/text()")&.text,
|
@@ -272,14 +297,23 @@ module FB2rb
|
|
272
297
|
|
273
298
|
# Holds <document-info> data
|
274
299
|
class DocumentInfo
|
300
|
+
# @return [Array<FB2rb::Author>]
|
275
301
|
attr_accessor(:authors)
|
302
|
+
# @return [String, nil]
|
276
303
|
attr_accessor(:program_used)
|
304
|
+
# @return [FB2rb::FB2Date]
|
277
305
|
attr_accessor(:date)
|
306
|
+
# @return [Array<String>]
|
278
307
|
attr_accessor(:src_urls)
|
308
|
+
# @return [String, nil]
|
279
309
|
attr_accessor(:src_ocr)
|
310
|
+
# @return [String]
|
280
311
|
attr_accessor(:id)
|
312
|
+
# @return [String]
|
281
313
|
attr_accessor(:version)
|
314
|
+
# @return [String, nil]
|
282
315
|
attr_accessor(:history)
|
316
|
+
# @return [Array<String>]
|
283
317
|
attr_accessor(:publishers)
|
284
318
|
|
285
319
|
def initialize(authors = [], # rubocop:disable Metrics/ParameterLists
|
@@ -302,6 +336,7 @@ module FB2rb
|
|
302
336
|
@publishers = publishers
|
303
337
|
end
|
304
338
|
|
339
|
+
# @return [FB2rb::DocumentInfo]
|
305
340
|
def self.parse(xml, fb2_prefix) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
|
306
341
|
date = xml.at("./#{fb2_prefix}:date")
|
307
342
|
DocumentInfo.new(
|
@@ -314,11 +349,12 @@ module FB2rb
|
|
314
349
|
xml.at("./#{fb2_prefix}:src-ocr")&.text,
|
315
350
|
xml.at("./#{fb2_prefix}:id").text,
|
316
351
|
xml.at("./#{fb2_prefix}:version")&.text,
|
317
|
-
xml.at("./#{fb2_prefix}:history")&.children&.to_s&.strip
|
352
|
+
xml.at("./#{fb2_prefix}:history")&.children&.to_s&.strip,
|
353
|
+
xml.xpath("./#{fb2_prefix}:publisher").map(&:text)
|
318
354
|
)
|
319
355
|
end
|
320
356
|
|
321
|
-
def to_xml(xml) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
357
|
+
def to_xml(xml) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
|
322
358
|
xml.send(:'document-info') do
|
323
359
|
@authors.each do |author|
|
324
360
|
author.to_xml(xml, 'author')
|
@@ -336,22 +372,36 @@ module FB2rb
|
|
336
372
|
xml << @history
|
337
373
|
end
|
338
374
|
end
|
375
|
+
@publishers.each do |publisher|
|
376
|
+
xml.publisher(publisher)
|
377
|
+
end
|
339
378
|
end
|
340
379
|
end
|
341
380
|
end
|
342
381
|
|
343
382
|
# Holds <title-info>/<src-title-info> data
|
344
383
|
class TitleInfo
|
384
|
+
# @return [Array<String>]
|
345
385
|
attr_accessor(:genres)
|
386
|
+
# @return [Array<FB2rb::Author>]
|
346
387
|
attr_accessor(:authors)
|
388
|
+
# @return [String]
|
347
389
|
attr_accessor(:book_title)
|
390
|
+
# @return [String, nil]
|
348
391
|
attr_accessor(:annotation)
|
392
|
+
# @return [Array<String>]
|
349
393
|
attr_accessor(:keywords)
|
394
|
+
# @return [String, nil]
|
350
395
|
attr_accessor(:date)
|
396
|
+
# @return [FB2rb::Coverpage, nil]
|
351
397
|
attr_accessor(:coverpage)
|
398
|
+
# @return [String]
|
352
399
|
attr_accessor(:lang)
|
400
|
+
# @return [String, nil]
|
353
401
|
attr_accessor(:src_lang)
|
402
|
+
# @return [Array<FB2rb::Author>]
|
354
403
|
attr_accessor(:translators)
|
404
|
+
# @return [Array<FB2rb::Sequence>]
|
355
405
|
attr_accessor(:sequences)
|
356
406
|
|
357
407
|
def initialize(genres = [], # rubocop:disable Metrics/MethodLength, Metrics/ParameterLists
|
@@ -378,6 +428,7 @@ module FB2rb
|
|
378
428
|
@sequences = sequences
|
379
429
|
end
|
380
430
|
|
431
|
+
# @return [FB2rb::TitleInfo]
|
381
432
|
def self.parse(xml, fb2_prefix, xlink_prefix) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
|
382
433
|
date = xml.at("./#{fb2_prefix}:date")
|
383
434
|
coverpage = xml.at("./#{fb2_prefix}:coverpage")
|
@@ -433,6 +484,7 @@ module FB2rb
|
|
433
484
|
|
434
485
|
# Holds <coverpage> data
|
435
486
|
class Coverpage
|
487
|
+
# @return [Array<String>]
|
436
488
|
attr_accessor(:images)
|
437
489
|
|
438
490
|
def initialize(images = [])
|
@@ -456,7 +508,9 @@ module FB2rb
|
|
456
508
|
|
457
509
|
# Holds <date> data
|
458
510
|
class FB2Date
|
511
|
+
# @return [String]
|
459
512
|
attr_accessor(:display_value)
|
513
|
+
# @return [Date, nil]
|
460
514
|
attr_accessor(:value)
|
461
515
|
|
462
516
|
def initialize(display_value = '', value = nil)
|
@@ -481,7 +535,9 @@ module FB2rb
|
|
481
535
|
|
482
536
|
# Holds <sequence> data
|
483
537
|
class Sequence
|
538
|
+
# @return [String]
|
484
539
|
attr_accessor(:name)
|
540
|
+
# @return [Integer, nil]
|
485
541
|
attr_accessor(:number)
|
486
542
|
|
487
543
|
def initialize(name = '', number = nil)
|
@@ -489,6 +545,7 @@ module FB2rb
|
|
489
545
|
@number = number
|
490
546
|
end
|
491
547
|
|
548
|
+
# @return [FB2rb::Sequence]
|
492
549
|
def self.parse(xml)
|
493
550
|
Sequence.new(xml['name'], xml['number']&.to_i)
|
494
551
|
end
|
@@ -502,12 +559,19 @@ module FB2rb
|
|
502
559
|
|
503
560
|
# Holds <author> data
|
504
561
|
class Author
|
562
|
+
# @return [String, nil]
|
505
563
|
attr_accessor(:first_name)
|
564
|
+
# @return [String, nil]
|
506
565
|
attr_accessor(:middle_name)
|
566
|
+
# @return [String, nil]
|
507
567
|
attr_accessor(:last_name)
|
568
|
+
# @return [String, nil]
|
508
569
|
attr_accessor(:nickname)
|
570
|
+
# @return [Array<String>]
|
509
571
|
attr_accessor(:home_pages)
|
572
|
+
# @return [Array<String>]
|
510
573
|
attr_accessor(:emails)
|
574
|
+
# @return [String, nil]
|
511
575
|
attr_accessor(:id)
|
512
576
|
|
513
577
|
def initialize(first_name = nil, # rubocop:disable Metrics/ParameterLists
|
@@ -526,6 +590,7 @@ module FB2rb
|
|
526
590
|
@id = id
|
527
591
|
end
|
528
592
|
|
593
|
+
# @return [FB2rb::Author]
|
529
594
|
def self.parse(xml, fb2_prefix) # rubocop:disable Metrics/CyclomaticComplexity
|
530
595
|
Author.new(
|
531
596
|
xml.at("./#{fb2_prefix}:first-name/text()")&.text,
|
@@ -557,7 +622,9 @@ module FB2rb
|
|
557
622
|
|
558
623
|
# Holds <body> data
|
559
624
|
class Body
|
625
|
+
# @return [String, nil]
|
560
626
|
attr_accessor(:name)
|
627
|
+
# @return [String]
|
561
628
|
attr_accessor(:content)
|
562
629
|
|
563
630
|
def initialize(name = nil, content = '')
|
@@ -565,6 +632,7 @@ module FB2rb
|
|
565
632
|
@content = content
|
566
633
|
end
|
567
634
|
|
635
|
+
# @return [FB2rb::Body]
|
568
636
|
def self.parse(xml)
|
569
637
|
Body.new(
|
570
638
|
xml['name'],
|
@@ -584,12 +652,15 @@ module FB2rb
|
|
584
652
|
|
585
653
|
# Holds data of a single binary within FB2 file
|
586
654
|
class Binary
|
655
|
+
# @return [String]
|
587
656
|
attr_accessor(:id)
|
657
|
+
# @return [String]
|
588
658
|
attr_accessor(:content)
|
659
|
+
# @return [String, nil]
|
589
660
|
attr_accessor(:content_type)
|
590
661
|
|
591
|
-
def initialize(
|
592
|
-
@id =
|
662
|
+
def initialize(id, content, content_type = nil)
|
663
|
+
@id = id
|
593
664
|
@content = content
|
594
665
|
@content_type = content_type
|
595
666
|
end
|
data/lib/fb2rb/version.rb
CHANGED