Class: FB2rb::Binary

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

Overview

Holds data of a single binary within FB2 file

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id: nil, content: ''.b, content_type: nil) ⇒ Binary

Returns a new instance of Binary.



710
711
712
713
714
# File 'lib/fb2rb.rb', line 710

def initialize(id: nil, content: ''.b, content_type: nil)
  @id = id
  @content = content
  @content_type = content_type
end

Instance Attribute Details

#contentString

Returns:

  • (String)


706
707
708
# File 'lib/fb2rb.rb', line 706

def content
  @content
end

#content_typeString?

Returns:

  • (String, nil)


708
709
710
# File 'lib/fb2rb.rb', line 708

def content_type
  @content_type
end

#idString

Returns:

  • (String)


704
705
706
# File 'lib/fb2rb.rb', line 704

def id
  @id
end

Class Method Details

.parse(xml) ⇒ Object



716
717
718
719
# File 'lib/fb2rb.rb', line 716

def self.parse(xml)
  decoded = xml.text.unpack('m0')[0]
  Binary.new(id: xml['id'], content: decoded, content_type: xml['content-type'])
end

Instance Method Details

#to_xml(xml) ⇒ Object



721
722
723
724
# File 'lib/fb2rb.rb', line 721

def to_xml(xml)
  encoded = [@content].pack('m0')
  xml.binary(encoded, 'id' => @id, 'content-type' => @content_type)
end