Module: TSparser::Parsing
- Included in:
- AdaptationField, AudioComponentDescriptor, CAContractInformationDescriptor, ComponentDescriptor, ContentDescriptor, ContentDescriptor::ContentList::Content, DataContentDescriptor, DigitalCopyControlDescriptor, EITEvent, EventGroupDescriptor, EventInformationSection, ExtendedEventDescriptor, ExtendedEventDescriptor::ItemHash::Item, ShortEventDescriptor, TransportPacket, UnknownDescriptor
- Defined in:
- lib/parsing.rb
Defined Under Namespace
Modules: ClassExtension
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/parsing.rb', line 32
def method_missing(name, *args)
if @parsing_proc
parsing_proc = @parsing_proc
@parsing_proc = nil
self.instance_eval(&parsing_proc)
end
if @parsed_variable[name]
if @parsed_variable[name].instance_of?(Proc)
@parsed_variable[name] = @parsed_variable[name].call
end
return @parsed_variable[name]
end
super
end
|
Class Method Details
.included(klass) ⇒ Object
47
48
49
|
# File 'lib/parsing.rb', line 47
def self.included(klass)
klass.extend ClassExtension
end
|
Instance Method Details
#initialize(binary, parsing_proc = nil, delay = true) ⇒ Object
5
6
7
8
9
10
11
12
13
|
# File 'lib/parsing.rb', line 5
def initialize(binary, parsing_proc=nil, delay=true)
@binary = binary
@parsed_variable = Hash.new
if delay
@parsing_proc = parsing_proc
else
self.instance_eval(&parsing_proc) if parsing_proc
end
end
|
#read(name, type, bit) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/parsing.rb', line 15
def read(name, type, bit)
if type == Integer
val = @binary.read_bit_as_integer(bit)
@parsed_variable[name] = val
else
val = @binary.read_bit_as_binary(bit)
@parsed_variable[name] = Proc.new{ type.new(val) }
end
rescue => error
STDERR.puts "Parsing error occurred at class: #{self.class}, attr: #{name}(type:#{type}, bitlen:#{bit})"
raise error
end
|
#rest_all ⇒ Object
28
29
30
|
# File 'lib/parsing.rb', line 28
def rest_all
return @binary.rest_readable_bit_length
end
|