Class: IFF::Chunk

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

Overview

A generic representation for a YAML chunk; its payload is accessible via the ‘content’ accessor.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

iff_tag

Constructor Details

#initialize(tag, content = nil) ⇒ Chunk

Returns a new instance of Chunk.



41
42
43
44
# File 'lib/iff.rb', line 41

def initialize( tag, content=nil )
  @tag = tag
  @content = content.to_s
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



32
33
34
# File 'lib/iff.rb', line 32

def content
  @content
end

#tagObject (readonly)

Returns the value of attribute tag.



31
32
33
# File 'lib/iff.rb', line 31

def tag
  @tag
end

Class Method Details

.unserialize(tag, length, stream, options) ⇒ Object

Raises:

  • (EOFError)


34
35
36
37
38
39
# File 'lib/iff.rb', line 34

def self.unserialize( tag, length, stream, options )
  content = stream.read( length )
  raise EOFError, "Body too short" \
    if !content || content.length < length
  self.new( tag, content )
end

Instance Method Details

#serialize(stream, options) ⇒ Object



46
47
48
# File 'lib/iff.rb', line 46

def serialize( stream, options )
  stream << content
end