Class: MediaInfoNative::StreamProxy
- Inherits:
-
Object
- Object
- MediaInfoNative::StreamProxy
show all
- Includes:
- Enumerable
- Defined in:
- lib/mediainfo-native/mediainfo.rb
Constant Summary
collapse
- SingleStreamAPIError =
Class.new(RuntimeError)
- NoStreamsForProxyError =
Class.new(NoMethodError)
- UnknownAttributeError =
Class.new(NoMethodError)
Instance Method Summary
collapse
Constructor Details
#initialize(streams) ⇒ StreamProxy
Returns a new instance of StreamProxy.
40
41
42
|
# File 'lib/mediainfo-native/mediainfo.rb', line 40
def initialize(streams)
@streams = streams
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *a, &b) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/mediainfo-native/mediainfo.rb', line 70
def method_missing(m, *a, &b)
case @streams.size
when 0
raise NoStreamsForProxyError
when 1
if @streams.first.respond_to?(m)
@streams.first.send(m, *a, &b)
else
raise UnknownAttributeError
end
else
raise SingleStreamAPIError
end
end
|
Instance Method Details
#[](idx) ⇒ Object
48
|
# File 'lib/mediainfo-native/mediainfo.rb', line 48
def [](idx); @streams[idx]; end
|
#count ⇒ Object
49
|
# File 'lib/mediainfo-native/mediainfo.rb', line 49
def count; @streams.size; end
|
#each(&blk) ⇒ Object
51
52
53
|
# File 'lib/mediainfo-native/mediainfo.rb', line 51
def each(&blk)
@streams.each(&blk)
end
|
#respond_to?(meth, include_all = false) ⇒ Boolean
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/mediainfo-native/mediainfo.rb', line 55
def respond_to?(meth, include_all = false)
begin
case @streams.size
when 0
false
when 1
@streams.first.respond_to?(meth, include_all)
when [:[], :count].include?(meth)
true
else
raise SingleStreamAPIError
end
end || super
end
|