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.



630
631
632
633
# File 'lib/fb2rb.rb', line 630

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

Instance Attribute Details

#contentString

Returns:

  • (String)


628
629
630
# File 'lib/fb2rb.rb', line 628

def content
  @content
end

#nameString?

Returns:

  • (String, nil)


626
627
628
# File 'lib/fb2rb.rb', line 626

def name
  @name
end

Class Method Details

.parse(xml) ⇒ FB2rb::Body

Returns:



636
637
638
639
640
641
# File 'lib/fb2rb.rb', line 636

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

Instance Method Details

#to_xml(xml) ⇒ Object



643
644
645
646
647
648
649
650
# File 'lib/fb2rb.rb', line 643

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

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