Class: FB2rb::Body

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

Overview

Holds <body> data

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = nil, content = '') ⇒ Body

Returns a new instance of Body.



660
661
662
663
# File 'lib/fb2rb.rb', line 660

def initialize(name = nil, content = '')
  @name = name
  @content = content
end

Instance Attribute Details

#contentString

Returns:

  • (String)


658
659
660
# File 'lib/fb2rb.rb', line 658

def content
  @content
end

#nameString?

Returns:

  • (String, nil)


656
657
658
# File 'lib/fb2rb.rb', line 656

def name
  @name
end

Class Method Details

.parse(xml) ⇒ FB2rb::Body

Returns:



666
667
668
669
670
671
# File 'lib/fb2rb.rb', line 666

def self.parse(xml)
  Body.new(
    xml['name'],
    xml.children.to_s.strip
  )
end

Instance Method Details

#to_xml(xml) ⇒ Object



673
674
675
676
677
678
679
680
# File 'lib/fb2rb.rb', line 673

def to_xml(xml)
  return if @content.nil?

  xml.body do
    xml.parent['name'] = @name unless @name.nil?
    xml << @content
  end
end