Class: Vidibus::Encoder::Util::Profiles

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/vidibus/encoder/util/profiles.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options)
  @base = options[:base]
  @profile = options[:profile]
  @profiles = options[:profiles]
end

Instance Attribute Details

#baseObject (readonly)

Returns the value of attribute base.



7
8
9
# File 'lib/vidibus/encoder/util/profiles.rb', line 7

def base
  @base
end

#profileObject (readonly)

Returns the value of attribute profile.



7
8
9
# File 'lib/vidibus/encoder/util/profiles.rb', line 7

def profile
  @profile
end

#profilesObject (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

#availableObject

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

#collectionHash Also known as: to_h

Return the used profile(s). If no profile is used, an empty hash will be returned.

Returns:

  • (Hash)

    A collection of profile objects



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

#eachObject

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.

Returns:

  • (Boolean)


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

#validateObject

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