Module: BMFF::Box::Container

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



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

def children
  @children
end

Instance Method Details

#add_child(child) ⇒ Object



22
23
24
25
# File 'lib/bmff/box/container.rb', line 22

def add_child(child)
  @children ||= []
  @children << child
end

#container?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/bmff/box/container.rb', line 7

def container?
  true
end

#find(boxtype) ⇒ Object

Find a box which has a specific type from my children.



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/bmff/box/container.rb', line 28

def find(boxtype)
  (@children || []).each do |child|
    case boxtype
    when String
      return child if child.type == boxtype
    when Class
      return child if child.kind_of?(boxtype)
    end
  end
  nil
end

#find_all(boxtype) ⇒ Object

Find boxes which have a specific type from my children.



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

def find_all(boxtype)
  found_boxes = []
  (@children || []).each do |child|
    case boxtype
    when String
      found_boxes << child if child.type == boxtype
    when Class
      found_boxes << child if child.kind_of?(boxtype)
    end
  end
  found_boxes
end

#parse_childrenObject



11
12
13
14
15
16
# File 'lib/bmff/box/container.rb', line 11

def parse_children
  @children = []
  until eob?
    @children << BMFF::Box.get_box(io, self)
  end
end

#select_descendants(boxtype) ⇒ Object

Find boxes which have a specific type from my descendants.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/bmff/box/container.rb', line 55

def select_descendants(boxtype)
  selected_boxes = []
  (@children || []).each do |child|
    case boxtype
    when String
      selected_boxes << child if child.type == boxtype
    when Class
      selected_boxes << child if child.kind_of?(boxtype)
    end
    if child.container?
      selected_boxes.concat(child.select_descendants(boxtype))
    end
  end
  selected_boxes
end