Module: M3u8::Encryptable
- Includes:
- AttributeFormatter
- Included in:
- KeyItem, SessionKeyItem
- Defined in:
- lib/m3u8/encryptable.rb
Overview
Encapsulates logic common to encryption key tags. Adds :method, :uri, :iv, :key_format, and :key_format_versions accessors when included.
Instance Attribute Summary collapse
-
#iv ⇒ String?
Initialization vector.
-
#key_format ⇒ String?
KEYFORMAT value.
-
#key_format_versions ⇒ String?
KEYFORMATVERSIONS value.
-
#method ⇒ String?
Encryption method.
-
#uri ⇒ String?
Key URI.
Class Method Summary collapse
Instance Method Summary collapse
-
#attributes_to_s ⇒ String
Render encryption attributes as a comma-separated string.
-
#convert_key_names(attributes) ⇒ Hash
Map HLS attribute names to Ruby symbol keys.
-
#initialize(params = {}) ⇒ Object
Initialize from HLS attribute names or normalized symbol keys, storing only the normalized keys.
Methods included from AttributeFormatter
#boolean_format, #decimal_format, #quoted_format, #unquoted_format
Instance Attribute Details
#iv ⇒ String?
Returns initialization vector.
20 21 22 23 24 25 26 |
# File 'lib/m3u8/encryptable.rb', line 20 def self.included(base) base.send :attr_accessor, :method base.send :attr_accessor, :uri base.send :attr_accessor, :iv base.send :attr_accessor, :key_format base.send :attr_accessor, :key_format_versions end |
#key_format ⇒ String?
Returns KEYFORMAT value.
20 21 22 23 24 25 26 |
# File 'lib/m3u8/encryptable.rb', line 20 def self.included(base) base.send :attr_accessor, :method base.send :attr_accessor, :uri base.send :attr_accessor, :iv base.send :attr_accessor, :key_format base.send :attr_accessor, :key_format_versions end |
#key_format_versions ⇒ String?
Returns KEYFORMATVERSIONS value.
20 21 22 23 24 25 26 |
# File 'lib/m3u8/encryptable.rb', line 20 def self.included(base) base.send :attr_accessor, :method base.send :attr_accessor, :uri base.send :attr_accessor, :iv base.send :attr_accessor, :key_format base.send :attr_accessor, :key_format_versions end |
#method ⇒ String?
Returns encryption method.
20 21 22 23 24 25 26 |
# File 'lib/m3u8/encryptable.rb', line 20 def self.included(base) base.send :attr_accessor, :method base.send :attr_accessor, :uri base.send :attr_accessor, :iv base.send :attr_accessor, :key_format base.send :attr_accessor, :key_format_versions end |
#uri ⇒ String?
Returns key URI.
20 21 22 23 24 25 26 |
# File 'lib/m3u8/encryptable.rb', line 20 def self.included(base) base.send :attr_accessor, :method base.send :attr_accessor, :uri base.send :attr_accessor, :iv base.send :attr_accessor, :key_format base.send :attr_accessor, :key_format_versions end |
Class Method Details
.included(base) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/m3u8/encryptable.rb', line 20 def self.included(base) base.send :attr_accessor, :method base.send :attr_accessor, :uri base.send :attr_accessor, :iv base.send :attr_accessor, :key_format base.send :attr_accessor, :key_format_versions end |
Instance Method Details
#attributes_to_s ⇒ String
Render encryption attributes as a comma-separated string.
40 41 42 43 44 45 46 47 |
# File 'lib/m3u8/encryptable.rb', line 40 def attributes_to_s [unquoted_format('METHOD', method), quoted_format('URI', uri), unquoted_format('IV', iv), quoted_format('KEYFORMAT', key_format), quoted_format('KEYFORMATVERSIONS', key_format_versions)].compact.join(',') end |
#convert_key_names(attributes) ⇒ Hash
Map HLS attribute names to Ruby symbol keys.
52 53 54 55 56 |
# File 'lib/m3u8/encryptable.rb', line 52 def convert_key_names(attributes) { method: attributes['METHOD'], uri: attributes['URI'], iv: attributes['IV'], key_format: attributes['KEYFORMAT'], key_format_versions: attributes['KEYFORMATVERSIONS'] } end |
#initialize(params = {}) ⇒ Object
Initialize from HLS attribute names or normalized symbol keys, storing only the normalized keys.
31 32 33 34 35 36 |
# File 'lib/m3u8/encryptable.rb', line 31 def initialize(params = {}) convert_key_names(params).each do |key, value| value = params[key] if value.nil? instance_variable_set("@#{key}", value) end end |