Class: FB2rb::TitleInfo
- Inherits:
-
Object
- Object
- FB2rb::TitleInfo
- Defined in:
- lib/fb2rb.rb
Overview
Holds <title-info>/<src-title-info> data
Instance Attribute Summary collapse
- #annotation ⇒ String?
- #authors ⇒ Array<FB2rb::Author>
- #book_title ⇒ String
- #coverpage ⇒ FB2rb::Coverpage?
- #date ⇒ FB2rb::Date?
- #genres ⇒ Array<String>
- #keywords ⇒ Array<String>
- #lang ⇒ String
- #sequences ⇒ Array<FB2rb::Sequence>
- #src_lang ⇒ String?
- #translators ⇒ Array<FB2rb::Author>
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(genres: [], authors: [], book_title: '', annotation: nil, keywords: [], date: nil, coverpage: nil, lang: 'en', src_lang: nil, translators: [], sequences: []) ⇒ TitleInfo
constructor
rubocop:disable Metrics/MethodLength, Metrics/ParameterLists.
-
#to_xml(xml, tag) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity.
Constructor Details
#initialize(genres: [], authors: [], book_title: '', annotation: nil, keywords: [], date: nil, coverpage: nil, lang: 'en', src_lang: nil, translators: [], sequences: []) ⇒ TitleInfo
rubocop:disable Metrics/MethodLength, Metrics/ParameterLists
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 |
# File 'lib/fb2rb.rb', line 455 def initialize(genres: [], # rubocop:disable Metrics/MethodLength, Metrics/ParameterLists authors: [], book_title: '', annotation: nil, keywords: [], date: nil, coverpage: nil, lang: 'en', src_lang: nil, translators: [], sequences: []) @genres = genres @authors = @book_title = book_title @annotation = annotation @keywords = keywords @date = date @coverpage = coverpage @lang = lang @src_lang = src_lang @translators = translators @sequences = sequences end |
Instance Attribute Details
#annotation ⇒ String?
439 440 441 |
# File 'lib/fb2rb.rb', line 439 def annotation @annotation end |
#book_title ⇒ String
437 438 439 |
# File 'lib/fb2rb.rb', line 437 def book_title @book_title end |
#coverpage ⇒ FB2rb::Coverpage?
445 446 447 |
# File 'lib/fb2rb.rb', line 445 def coverpage @coverpage end |
#date ⇒ FB2rb::Date?
443 444 445 |
# File 'lib/fb2rb.rb', line 443 def date @date end |
#genres ⇒ Array<String>
433 434 435 |
# File 'lib/fb2rb.rb', line 433 def genres @genres end |
#keywords ⇒ Array<String>
441 442 443 |
# File 'lib/fb2rb.rb', line 441 def keywords @keywords end |
#lang ⇒ String
447 448 449 |
# File 'lib/fb2rb.rb', line 447 def lang @lang end |
#sequences ⇒ Array<FB2rb::Sequence>
453 454 455 |
# File 'lib/fb2rb.rb', line 453 def sequences @sequences end |
#src_lang ⇒ String?
449 450 451 |
# File 'lib/fb2rb.rb', line 449 def src_lang @src_lang end |
#translators ⇒ Array<FB2rb::Author>
451 452 453 |
# File 'lib/fb2rb.rb', line 451 def translators @translators end |
Class Method Details
.parse(xml, fb2_prefix, xlink_prefix) ⇒ FB2rb::TitleInfo
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 |
# File 'lib/fb2rb.rb', line 480 def self.parse(xml, fb2_prefix, xlink_prefix) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity date = xml.at("./#{fb2_prefix}:date") coverpage = xml.at("./#{fb2_prefix}:coverpage") TitleInfo.new( genres: xml.xpath("./#{fb2_prefix}:genre/text()").map(&:text), authors: xml.xpath("./#{fb2_prefix}:author").map do |node| Author.parse(node, fb2_prefix) end, book_title: xml.at("./#{fb2_prefix}:book-title/text()")&.text, annotation: xml.at("./#{fb2_prefix}:annotation")&.children.to_s.strip, keywords: xml.at("./#{fb2_prefix}:keywords/text()")&.text&.split(', ') || [], date: date.nil? ? nil : FB2Date.parse(date), coverpage: coverpage.nil? ? nil : Coverpage.parse(coverpage, fb2_prefix, xlink_prefix), lang: xml.at("./#{fb2_prefix}:lang/text()").text, src_lang: xml.at("./#{fb2_prefix}:src-lang/text()")&.text, translators: xml.xpath("./#{fb2_prefix}:translator").map do |node| Author.parse(node, fb2_prefix) end, sequences: xml.xpath("./#{fb2_prefix}:sequence").map do |node| Sequence.parse(node) end ) end |
Instance Method Details
#to_xml(xml, tag) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 |
# File 'lib/fb2rb.rb', line 504 def to_xml(xml, tag) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity xml.send(tag) do genres.each do |genre| xml.genre(genre) end .each do || .to_xml(xml, 'author') end xml.send('book-title', @book_title) unless @annotation.nil? xml.annotation do xml << @annotation end end xml.keywords(@keywords.join(', ')) unless keywords.nil? @date.to_xml(xml) unless date.nil? @coverpage.to_xml(xml) unless coverpage.nil? xml.lang(@lang) xml.send('src-lang') unless src_lang.nil? @translators.each do |translator| translator.to_xml(xml, 'translator') end @sequences.each do |sequence| sequence.to_xml(xml) end end end |