Class: BMFF::Box::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/bmff/box/base.rb

Overview

vim: set expandtab tabstop=2 shiftwidth=2 softtabstop=2 autoindent:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#ioObject

Returns the value of attribute io.



5
6
7
# File 'lib/bmff/box/base.rb', line 5

def io
  @io
end

#largesizeObject

Returns the value of attribute largesize.



5
6
7
# File 'lib/bmff/box/base.rb', line 5

def largesize
  @largesize
end

#offsetObject

Returns the value of attribute offset.



5
6
7
# File 'lib/bmff/box/base.rb', line 5

def offset
  @offset
end

#parentObject

Returns the value of attribute parent.



5
6
7
# File 'lib/bmff/box/base.rb', line 5

def parent
  @parent
end

#sizeObject

Returns the value of attribute size.



5
6
7
# File 'lib/bmff/box/base.rb', line 5

def size
  @size
end

#typeObject

Returns the value of attribute type.



5
6
7
# File 'lib/bmff/box/base.rb', line 5

def type
  @type
end

#usertypeObject

Returns the value of attribute usertype.



5
6
7
# File 'lib/bmff/box/base.rb', line 5

def usertype
  @usertype
end

Class Method Details

.register_box(*boxtypes) ⇒ Object



8
9
10
11
12
# File 'lib/bmff/box/base.rb', line 8

def self.register_box(*boxtypes)
  boxtypes.each do |boxtype|
    BMFF::Box::Map.register_box(boxtype, self)
  end
end

Instance Method Details

#actual_sizeObject



14
15
16
17
18
# File 'lib/bmff/box/base.rb', line 14

def actual_size
  return largesize if size == 1
  return nil if size == 0
  return size
end

#container?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/bmff/box/base.rb', line 63

def container?
  false
end

#eob?Boolean

end of box?

Returns:

  • (Boolean)


28
29
30
31
32
33
34
# File 'lib/bmff/box/base.rb', line 28

def eob?
  if actual_size
    return io.pos >= offset + actual_size
  else
    return io.eof?
  end
end

#parseObject



44
45
46
47
48
49
50
51
52
# File 'lib/bmff/box/base.rb', line 44

def parse
  parse_data
  if actual_size
    if io.pos > offset + actual_size
      raise RangeError, "Given box size is smaller than expected."
    end
  end
  seek_to_end
end

#parse_dataObject



54
55
56
57
58
59
60
61
# File 'lib/bmff/box/base.rb', line 54

def parse_data
  if size == 1
    @largesize = io.get_uint64
  end
  if type == 'uuid'
    @usertype = io.get_uuid
  end
end

#remaining_sizeObject



20
21
22
23
24
25
# File 'lib/bmff/box/base.rb', line 20

def remaining_size
  if actual_size
    return (offset + actual_size) - io.pos
  end
  nil
end

#seek_to_endObject



36
37
38
39
40
41
42
# File 'lib/bmff/box/base.rb', line 36

def seek_to_end
  if actual_size
    io.pos = offset + actual_size
  else
    io.seek(0, IO::SEEK_END)
  end
end