Module: M3u8::AttributeFormatter
- Included in:
- ContentSteeringItem, DateRangeItem, Encryptable, MapItem, MediaItem, PartItem, PlaybackStart, PlaylistItem, PreloadHintItem, RenditionReportItem, SegmentItem, ServerControlItem, SessionDataItem, SkipItem
- Defined in:
- lib/m3u8/attribute_formatter.rb
Overview
Shared helpers for formatting HLS tag attributes
Instance Method Summary collapse
-
#boolean_format(key, value) ⇒ String?
Format a YES/NO boolean attribute (e.g. KEY=YES).
-
#decimal_format(number) ⇒ String?
Format a decimal attribute, ensuring it formatted as a floating-point number or integer.
-
#quoted_format(key, value) ⇒ String?
Format a quoted attribute (e.g. KEY=“value”).
-
#unquoted_format(key, value) ⇒ String?
Format an unquoted attribute (e.g. KEY=value).
Instance Method Details
#boolean_format(key, value) ⇒ String?
Format a YES/NO boolean attribute (e.g. KEY=YES).
28 29 30 |
# File 'lib/m3u8/attribute_formatter.rb', line 28 def boolean_format(key, value) "#{key}=#{value == true ? 'YES' : 'NO'}" unless value.nil? end |
#decimal_format(number) ⇒ String?
Format a decimal attribute, ensuring it formatted as a floating-point number or integer
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/m3u8/attribute_formatter.rb', line 36 def decimal_format(number) case number when nil nil when Float BigDecimal(number).to_s('F') else number.to_s end end |
#quoted_format(key, value) ⇒ String?
Format a quoted attribute (e.g. KEY=“value”).
12 13 14 |
# File 'lib/m3u8/attribute_formatter.rb', line 12 def quoted_format(key, value) %(#{key}="#{value}") unless value.nil? end |
#unquoted_format(key, value) ⇒ String?
Format an unquoted attribute (e.g. KEY=value).
20 21 22 |
# File 'lib/m3u8/attribute_formatter.rb', line 20 def unquoted_format(key, value) "#{key}=#{value}" unless value.nil? end |