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
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 |
# File 'lib/fb2rb.rb', line 349 def initialize( = [], # rubocop:disable Metrics/ParameterLists program_used = nil, date = FB2Date.new, src_urls = [], src_ocr = nil, id = '', version = '', history = nil, publishers = []) @authors = @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?
345 346 347 |
# File 'lib/fb2rb.rb', line 345 def history @history end |
#id ⇒ String
341 342 343 |
# File 'lib/fb2rb.rb', line 341 def id @id end |
#program_used ⇒ String?
333 334 335 |
# File 'lib/fb2rb.rb', line 333 def program_used @program_used end |
#publishers ⇒ Array<String>
347 348 349 |
# File 'lib/fb2rb.rb', line 347 def publishers @publishers end |
#src_ocr ⇒ String?
339 340 341 |
# File 'lib/fb2rb.rb', line 339 def src_ocr @src_ocr end |
#src_urls ⇒ Array<String>
337 338 339 |
# File 'lib/fb2rb.rb', line 337 def src_urls @src_urls end |
#version ⇒ String
343 344 345 |
# File 'lib/fb2rb.rb', line 343 def version @version end |
Class Method Details
.parse(xml, fb2_prefix) ⇒ FB2rb::DocumentInfo
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 |
# File 'lib/fb2rb.rb', line 370 def self.parse(xml, fb2_prefix) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength date = xml.at("./#{fb2_prefix}:date") DocumentInfo.new( xml.xpath("./#{fb2_prefix}:author").map do |node| Author.parse(node, fb2_prefix) end, xml.at("./#{fb2_prefix}:program-used")&.text, date.nil? ? FB2Date.new : FB2Date.parse(date), xml.xpath("./#{fb2_prefix}:src-url").map(&:text), xml.at("./#{fb2_prefix}:src-ocr")&.text, xml.at("./#{fb2_prefix}:id").text, xml.at("./#{fb2_prefix}:version")&.text, xml.at("./#{fb2_prefix}:history")&.children&.to_s&.strip, xml.xpath("./#{fb2_prefix}:publisher").map(&:text) ) end |
Instance Method Details
#to_xml(xml) ⇒ Object
rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 |
# File 'lib/fb2rb.rb', line 387 def to_xml(xml) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength xml.send(:'document-info') do @authors.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 |