Class: FB2rb::PublishInfo
- Inherits:
-
Object
- Object
- FB2rb::PublishInfo
- Defined in:
- lib/fb2rb.rb
Overview
Holds <publish-info> data
Instance Attribute Summary collapse
- #book_name ⇒ String?
- #city ⇒ String?
- #isbn ⇒ String?
- #publisher ⇒ String?
- #sequences ⇒ Array<FB2RB::Sequence>
- #year ⇒ String?
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(book_name: nil, publisher: nil, city: nil, year: nil, isbn: nil, sequences: []) ⇒ PublishInfo
constructor
rubocop:disable Metrics/ParameterLists.
- #to_xml(xml) ⇒ Object
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_name ⇒ String?
292 293 294 |
# File 'lib/fb2rb.rb', line 292 def book_name @book_name end |
#city ⇒ String?
296 297 298 |
# File 'lib/fb2rb.rb', line 296 def city @city end |
#isbn ⇒ String?
300 301 302 |
# File 'lib/fb2rb.rb', line 300 def isbn @isbn end |
#publisher ⇒ String?
294 295 296 |
# File 'lib/fb2rb.rb', line 294 def publisher @publisher end |
#sequences ⇒ Array<FB2RB::Sequence>
302 303 304 |
# File 'lib/fb2rb.rb', line 302 def sequences @sequences end |
#year ⇒ String?
298 299 300 |
# File 'lib/fb2rb.rb', line 298 def year @year end |
Class Method Details
.parse(xml, fb2_prefix) ⇒ 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 |