Class: FB2rb::PublishInfo

Inherits:
Object
  • Object
show all
Defined in:
lib/fb2rb.rb

Overview

Holds <publish-info> data

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(book_name: nil, publisher: nil, city: nil, year: nil, isbn: nil, sequences: []) ⇒ PublishInfo

rubocop:disable Metrics/ParameterLists



304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'lib/fb2rb.rb', line 304

def initialize(book_name: nil, # rubocop:disable Metrics/ParameterLists
               publisher: nil,
               city: nil,
               year: nil,
               isbn: nil,
               sequences: [])
  @book_name = book_name
  @publisher = publisher
  @city = city
  @year = year
  @isbn = isbn
  @sequences = sequences
end

Instance Attribute Details

#book_nameString?

Returns:

  • (String, nil)


292
293
294
# File 'lib/fb2rb.rb', line 292

def book_name
  @book_name
end

#cityString?

Returns:

  • (String, nil)


296
297
298
# File 'lib/fb2rb.rb', line 296

def city
  @city
end

#isbnString?

Returns:

  • (String, nil)


300
301
302
# File 'lib/fb2rb.rb', line 300

def isbn
  @isbn
end

#publisherString?

Returns:

  • (String, nil)


294
295
296
# File 'lib/fb2rb.rb', line 294

def publisher
  @publisher
end

#sequencesArray<FB2RB::Sequence>

Returns:

  • (Array<FB2RB::Sequence>)


302
303
304
# File 'lib/fb2rb.rb', line 302

def sequences
  @sequences
end

#yearString?

Returns:

  • (String, nil)


298
299
300
# File 'lib/fb2rb.rb', line 298

def year
  @year
end

Class Method Details

.parse(xml, fb2_prefix) ⇒ FB2RB::PublishInfo

Returns:

  • (FB2RB::PublishInfo)


319
320
321
322
323
324
325
326
327
328
329
330
# File 'lib/fb2rb.rb', line 319

def self.parse(xml, fb2_prefix)
  PublishInfo.new(
    book_name: xml.at("./#{fb2_prefix}:book-name/text()")&.text,
    publisher: xml.at("./#{fb2_prefix}:publisher/text()")&.text,
    city: xml.at("./#{fb2_prefix}:city/text()")&.text,
    year: xml.at("./#{fb2_prefix}:year/text()")&.text,
    isbn: xml.at("./#{fb2_prefix}:isbn/text()")&.text,
    sequences: xml.xpath("./#{fb2_prefix}:sequence").map do |node|
      Sequence.parse(node)
    end
  )
end

Instance Method Details

#to_xml(xml) ⇒ Object



332
333
334
335
336
337
338
339
340
341
342
343
# File 'lib/fb2rb.rb', line 332

def to_xml(xml)
  xml.send('publish-info') do
    xml.send('book-name', @book_name) unless @book_name.nil?
    xml.publisher(@publisher) unless @publisher.nil?
    xml.city(@city) unless @city.nil?
    xml.year(@year) unless @year.nil?
    xml.isbn(@isbn) unless @isbn.nil?
    @sequences.each do |sequence|
      sequence.to_xml(xml)
    end
  end
end