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.
91 92 93 94 95 96 97 98 99 |
# File 'lib/mediainfo.rb', line 91 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
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/mediainfo.rb', line 109 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.
104 105 106 |
# File 'lib/mediainfo.rb', line 104 def stream_type @stream_type end |
#streams ⇒ Object (readonly)
Returns the value of attribute streams.
103 104 105 |
# File 'lib/mediainfo.rb', line 103 def streams @streams end |
Instance Method Details
#[](id) ⇒ Object
101 |
# File 'lib/mediainfo.rb', line 101 def [](id); @streams[id]; end |
#count ⇒ Object
102 |
# File 'lib/mediainfo.rb', line 102 def count; @streams.size; end |