Class: Caf::Chunk::Base
- Inherits:
-
Object
show all
- Defined in:
- lib/caf/chunk/base.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(chunk_header) ⇒ Base
Returns a new instance of Base.
16
17
18
19
|
# File 'lib/caf/chunk/base.rb', line 16
def initialize()
@chunk_type = [:chunk_type]
@chunk_size = [:chunk_size]
end
|
Instance Attribute Details
#chunk_size ⇒ Object
Returns the value of attribute chunk_size.
14
15
16
|
# File 'lib/caf/chunk/base.rb', line 14
def chunk_size
@chunk_size
end
|
#chunk_type ⇒ Object
Returns the value of attribute chunk_type.
14
15
16
|
# File 'lib/caf/chunk/base.rb', line 14
def chunk_type
@chunk_type
end
|
Class Method Details
.implements(chunk_type) ⇒ Object
Instance Method Details
#check_type_and_size(expected_klass, expected_chunk_type) ⇒ Object
38
39
40
41
|
# File 'lib/caf/chunk/base.rb', line 38
def check_type_and_size(expected_klass, expected_chunk_type)
raise(Caf::Error, "expected an #{expected_chunk_type} chunk") unless self.instance_of?(expected_klass)
raise(Caf::Error, "corrupted chunk: wrong size (expected #{fields_size}, got #{chunk_size}") if fields_size != chunk_size
end
|
#fields_size ⇒ Object
30
31
32
|
# File 'lib/caf/chunk/base.rb', line 30
def fields_size
raise(Caf::Error, "chunk must implement fields_size method: #{chunk_type}") unless self.instance_of?(Base)
end
|
#read_data(file) ⇒ Object
34
35
36
|
# File 'lib/caf/chunk/base.rb', line 34
def read_data(file)
file.seek(chunk_size, IO::SEEK_CUR) unless chunk_size == -1
end
|
#to_s ⇒ Object
21
22
23
|
# File 'lib/caf/chunk/base.rb', line 21
def to_s
"#{chunk_type} (unknown chunk)"
end
|
#validate ⇒ Object
25
26
27
28
|
# File 'lib/caf/chunk/base.rb', line 25
def validate
raise(Caf::Error, "chunk must implement validate method: #{chunk_type}") unless self.instance_of?(Base)
true
end
|