Class: Mediainfo::StreamProxy
- Inherits:
-
Object
- Object
- Mediainfo::StreamProxy
- Defined in:
- lib/mediainfo.rb
Defined Under Namespace
Classes: NoStreamsForProxyError, SingleStreamAPIError
Instance Attribute Summary collapse
-
#stream_type ⇒ Object
readonly
Returns the value of attribute stream_type.
-
#streams ⇒ Object
readonly
Returns the value of attribute streams.
Instance Method Summary collapse
- #[](id) ⇒ Object
- #count ⇒ Object
-
#initialize(mediainfo, stream_type) ⇒ StreamProxy
constructor
A new instance of StreamProxy.
- #method_missing(m, *a, &b) ⇒ Object
Constructor Details
#initialize(mediainfo, stream_type) ⇒ StreamProxy
Returns a new instance of StreamProxy.
125 126 127 128 129 130 131 132 133 |
# File 'lib/mediainfo.rb', line 125 def initialize(mediainfo, stream_type) unless Mediainfo::SECTIONS.include? stream_type raise ArgumentError, "invalid stream_type: #{stream_type.inspect}" end @stream_type = stream_type @mediainfo = mediainfo @streams = @mediainfo.streams.select { |x| x.send("#{stream_type}?") } end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *a, &b) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/mediainfo.rb', line 143 def method_missing(m, *a, &b) if streams.size > 1 raise SingleStreamAPIError, "You cannot use the single stream, convenience API on a multi-stream file." else if relevant_stream = streams.detect { |s| s.respond_to?(m) } relevant_stream.send(m, *a, &b) else raise NoStreamsForProxyError, "there are no :#{stream_type} streams to send :#{m} to" end end end |
Instance Attribute Details
#stream_type ⇒ Object (readonly)
Returns the value of attribute stream_type.
138 139 140 |
# File 'lib/mediainfo.rb', line 138 def stream_type @stream_type end |
#streams ⇒ Object (readonly)
Returns the value of attribute streams.
137 138 139 |
# File 'lib/mediainfo.rb', line 137 def streams @streams end |
Instance Method Details
#[](id) ⇒ Object
135 |
# File 'lib/mediainfo.rb', line 135 def [](id); @streams[id]; end |
#count ⇒ Object
136 |
# File 'lib/mediainfo.rb', line 136 def count; @streams.size; end |