Class: NuWav::Chunk
- Inherits:
-
Object
show all
- Defined in:
- lib/nu_wav/chunk.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(id = nil, size = nil, raw = nil) ⇒ Chunk
Returns a new instance of Chunk.
12
13
14
|
# File 'lib/nu_wav/chunk.rb', line 12
def initialize(id=nil, size=nil, raw=nil)
@id, @size, @raw = id, size, raw
end
|
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
3
4
5
|
# File 'lib/nu_wav/chunk.rb', line 3
def id
@id
end
|
#pad_byte ⇒ Object
Returns the value of attribute pad_byte.
3
4
5
|
# File 'lib/nu_wav/chunk.rb', line 3
def pad_byte
@pad_byte
end
|
#raw ⇒ Object
Returns the value of attribute raw.
3
4
5
|
# File 'lib/nu_wav/chunk.rb', line 3
def raw
@raw
end
|
#size ⇒ Object
Returns the value of attribute size.
3
4
5
|
# File 'lib/nu_wav/chunk.rb', line 3
def size
@size
end
|
Class Method Details
.parse(id, size, file) ⇒ Object
5
6
7
8
9
10
|
# File 'lib/nu_wav/chunk.rb', line 5
def self.parse(id, size, file)
raw = file.read(size)
chunk = self.new(id, size, raw)
chunk.parse
return chunk
end
|
Instance Method Details
#parse ⇒ Object
16
17
|
# File 'lib/nu_wav/chunk.rb', line 16
def parse
end
|
#read_char(start, length = (@raw.length-start)) ⇒ Object
27
28
29
|
# File 'lib/nu_wav/chunk.rb', line 27
def read_char(start, length=(@raw.length-start))
(@raw[start..(start+length-1)] || '').strip
end
|
#read_dword(start) ⇒ Object
19
20
21
|
# File 'lib/nu_wav/chunk.rb', line 19
def read_dword(start)
@raw[start..(start+3)].unpack('V').first
end
|
#read_word(start) ⇒ Object
23
24
25
|
# File 'lib/nu_wav/chunk.rb', line 23
def read_word(start)
@raw[start..(start+1)].unpack('v').first
end
|
#to_binary(options = {}) ⇒ Object
52
53
|
# File 'lib/nu_wav/chunk.rb', line 52
def to_binary(options={})
end
|
#write_char(val, length = nil) ⇒ Object
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/nu_wav/chunk.rb', line 41
def write_char(val, length=nil)
val ||= ''
val = val.to_s
length ||= val.length
padding = "\0" * [(length - val.length), 0].max
out = val[0,length] + padding
out
end
|
#write_dword(val) ⇒ Object
31
32
33
34
|
# File 'lib/nu_wav/chunk.rb', line 31
def write_dword(val)
val ||= 0
[val].pack('V')
end
|
#write_word(val) ⇒ Object
36
37
38
39
|
# File 'lib/nu_wav/chunk.rb', line 36
def write_word(val)
val ||= 0
[val].pack('v')
end
|