Class: Vidibus::Encoder::Util::Profiles
- Inherits:
-
Object
- Object
- Vidibus::Encoder::Util::Profiles
- Includes:
- Enumerable
- Defined in:
- lib/vidibus/encoder/util/profiles.rb
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#profile ⇒ Object
readonly
Returns the value of attribute profile.
-
#profiles ⇒ Object
readonly
Returns the value of attribute profiles.
Instance Method Summary collapse
-
#available ⇒ Object
Return all profiles available for encoder base.
-
#collection ⇒ Hash
(also: #to_h)
Return the used profile(s).
-
#each ⇒ Object
Iterate over the used profiles.
-
#initialize(options) ⇒ Profiles
constructor
A new instance of Profiles.
-
#multi? ⇒ Boolean
Return true if several profiles are in use.
-
#sorted(attribute = :bit_rate) ⇒ Object
Return the used profiles, sorted by given attribute.
-
#validate ⇒ Object
Return true if profile config is available, raise a ProfileError otherwise.
Constructor Details
#initialize(options) ⇒ Profiles
Returns a new instance of Profiles.
9 10 11 12 13 |
# File 'lib/vidibus/encoder/util/profiles.rb', line 9 def initialize() @base = [:base] @profile = [:profile] @profiles = [:profiles] end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
7 8 9 |
# File 'lib/vidibus/encoder/util/profiles.rb', line 7 def base @base end |
#profile ⇒ Object (readonly)
Returns the value of attribute profile.
7 8 9 |
# File 'lib/vidibus/encoder/util/profiles.rb', line 7 def profile @profile end |
#profiles ⇒ Object (readonly)
Returns the value of attribute profiles.
7 8 9 |
# File 'lib/vidibus/encoder/util/profiles.rb', line 7 def profiles @profiles end |
Instance Method Details
#available ⇒ Object
Return all profiles available for encoder base. For better encapsulation this method is placed here.
17 18 19 20 21 22 23 24 25 |
# File 'lib/vidibus/encoder/util/profiles.rb', line 17 def available @available ||= begin (base.class.registered_profiles || {}).tap do |items| if base.class.profile_presets items.merge!(base.class.profile_presets) end end end end |
#collection ⇒ Hash Also known as: to_h
Return the used profile(s). If no profile is used, an empty hash will be returned.
31 32 33 34 35 36 37 38 39 |
# File 'lib/vidibus/encoder/util/profiles.rb', line 31 def collection @collection ||= begin begin map rescue ProfileError {} end end end |
#each ⇒ Object
Iterate over the used profiles.
43 44 45 46 47 |
# File 'lib/vidibus/encoder/util/profiles.rb', line 43 def each collection.each do |profile| yield(profile) end end |
#multi? ⇒ Boolean
Return true if several profiles are in use.
66 67 68 |
# File 'lib/vidibus/encoder/util/profiles.rb', line 66 def multi? @is_multi ||= used.count > 1 end |
#sorted(attribute = :bit_rate) ⇒ Object
Return the used profiles, sorted by given attribute.
attribute [Hash] A collection of profile objects
Default sorting attribute is :bit_rate.
54 55 56 57 |
# File 'lib/vidibus/encoder/util/profiles.rb', line 54 def sorted(attribute = :bit_rate) @sorted ||= {} @sorted[attribute] ||= sort_by { |p| p.send(attribute) } end |
#validate ⇒ Object
Return true if profile config is available, raise a ProfileError otherwise.
61 62 63 |
# File 'lib/vidibus/encoder/util/profiles.rb', line 61 def validate !!map || raise(ProfileError, 'No profiles defined') end |