Class: FB2rb::DocumentInfo
- Inherits:
-
Object
- Object
- FB2rb::DocumentInfo
- Defined in:
- lib/fb2rb.rb
Overview
Holds <document-info> data
Instance Attribute Summary collapse
- #authors ⇒ Array<FB2rb::Author>
- #date ⇒ FB2rb::FB2Date
- #history ⇒ String?
- #id ⇒ String
- #program_used ⇒ String?
- #publishers ⇒ Array<String>
- #src_ocr ⇒ String?
- #src_urls ⇒ Array<String>
- #version ⇒ String
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(authors: [], program_used: nil, date: FB2Date.new, src_urls: [], src_ocr: nil, id: '', version: '', history: nil, publishers: []) ⇒ DocumentInfo
constructor
rubocop:disable Metrics/ParameterLists.
-
#to_xml(xml) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength.
Constructor Details
#initialize(authors: [], program_used: nil, date: FB2Date.new, src_urls: [], src_ocr: nil, id: '', version: '', history: nil, publishers: []) ⇒ DocumentInfo
rubocop:disable Metrics/ParameterLists
367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 |
# File 'lib/fb2rb.rb', line 367 def initialize(authors: [], # rubocop:disable Metrics/ParameterLists program_used: nil, date: FB2Date.new, src_urls: [], src_ocr: nil, id: '', version: '', history: nil, publishers: []) = @program_used = program_used @date = date @src_urls = src_urls @src_ocr = src_ocr @id = id @version = version @history = history @publishers = publishers end |
Instance Attribute Details
#history ⇒ String?
363 364 365 |
# File 'lib/fb2rb.rb', line 363 def history @history end |
#id ⇒ String
359 360 361 |
# File 'lib/fb2rb.rb', line 359 def id @id end |
#program_used ⇒ String?
351 352 353 |
# File 'lib/fb2rb.rb', line 351 def program_used @program_used end |
#publishers ⇒ Array<String>
365 366 367 |
# File 'lib/fb2rb.rb', line 365 def publishers @publishers end |
#src_ocr ⇒ String?
357 358 359 |
# File 'lib/fb2rb.rb', line 357 def src_ocr @src_ocr end |
#src_urls ⇒ Array<String>
355 356 357 |
# File 'lib/fb2rb.rb', line 355 def src_urls @src_urls end |
#version ⇒ String
361 362 363 |
# File 'lib/fb2rb.rb', line 361 def version @version end |
Class Method Details
.parse(xml, fb2_prefix) ⇒ FB2rb::DocumentInfo
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 |
# File 'lib/fb2rb.rb', line 388 def self.parse(xml, fb2_prefix) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity date = xml.at("./#{fb2_prefix}:date") DocumentInfo.new( authors: xml.xpath("./#{fb2_prefix}:author").map do |node| Author.parse(node, fb2_prefix) end, program_used: xml.at("./#{fb2_prefix}:program-used")&.text, date: date.nil? ? FB2Date.new : FB2Date.parse(date), src_urls: xml.xpath("./#{fb2_prefix}:src-url").map(&:text), src_ocr: xml.at("./#{fb2_prefix}:src-ocr")&.text, id: xml.at("./#{fb2_prefix}:id").text, version: xml.at("./#{fb2_prefix}:version")&.text, history: xml.at("./#{fb2_prefix}:history")&.children&.to_s&.strip, publishers: xml.xpath("./#{fb2_prefix}:publisher").map(&:text) ) end |
Instance Method Details
#to_xml(xml) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 |
# File 'lib/fb2rb.rb', line 405 def to_xml(xml) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength xml.send(:'document-info') do .each do || .to_xml(xml, 'author') end xml.send('program-used', @program_used) unless @program_used.nil? @date.to_xml(xml) @src_urls.each do |src_url| xml.send('src-url', src_url) end xml.send('src-ocr', @src_ocr) unless @src_ocr.nil? xml.id(@id) xml.version(@version) unless @version.nil? unless @history.nil? xml.history do xml << @history end end @publishers.each do |publisher| xml.publisher(publisher) end end end |