Module: FLV::Base

Included in:
Header, Tag
Defined in:
lib/flv/base.rb

Overview

Common fonctionality to both FLV::Header, FLV::Tag & FLV::Body

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
7
8
# File 'lib/flv/base.rb', line 4

def self.included(base)
  base.class_eval do
    include Packable
  end
end

Instance Method Details

#getters(of = self) ⇒ Object

returns the instance methods that are proper (i.e. not redefinitions) and that don’t require any argument.



13
14
15
16
17
18
# File 'lib/flv/base.rb', line 13

def getters(of=self)
  of.class.ancestors.
    map{|k| k.instance_methods(false)}.
    inject{|proper, methods| proper -= methods}.  # tricky: first ancestor is of.class, so that's what we start with
    select{|m| of.class.instance_method(m).arity.between?(-1,0)}
end

#is?(what) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
# File 'lib/flv/base.rb', line 27

def is?(what)
  kn = self.class.name.downcase
  [kn, kn.sub("flv::","")].include?(what.to_s.downcase)
end

#sizeObject



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

def size
  StringIO.new.packed.write(self)
end

#to_h(attributes = getters) ⇒ Object



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

def to_h(attributes = getters)
  Hash[attributes.map do |a|
    a = a.to_s.delete("@").to_sym
    [a, send(a)]
  end]
end