Class: EncodingDotCom::Format
- Inherits:
-
Object
- Object
- EncodingDotCom::Format
- Defined in:
- lib/encoding_dot_com/format.rb
Overview
Base class for all formats sent to encoding.com
You should create formats by calling create
with format attributes.
Direct Known Subclasses
Class Method Summary collapse
-
.allowed_attributes(*attrs) ⇒ Object
:nodoc:.
-
.boolean_attributes(*attrs) ⇒ Object
:nodoc:.
-
.create(attributes) ⇒ Object
Factory method that returns an appropriate Format.
Instance Method Summary collapse
-
#build_xml(builder, destination_url = nil) ⇒ Object
Builds the XML for this format.
Class Method Details
.allowed_attributes(*attrs) ⇒ Object
:nodoc:
22 23 24 25 26 27 28 29 |
# File 'lib/encoding_dot_com/format.rb', line 22 def allowed_attributes(*attrs) #:nodoc: @allowed_attributes ||= [] if attrs.empty? @allowed_attributes else @allowed_attributes += attrs.map {|a| a.to_s }.each { |attr| define_method(attr) { @attributes[attr] } } end end |
.boolean_attributes(*attrs) ⇒ Object
:nodoc:
31 32 33 34 35 36 37 38 39 |
# File 'lib/encoding_dot_com/format.rb', line 31 def boolean_attributes(*attrs) #:nodoc: @boolean_attributes ||= [] if attrs.empty? @boolean_attributes else allowed_attributes *attrs @boolean_attributes += attrs.map {|a| a.to_s } end end |
.create(attributes) ⇒ Object
Factory method that returns an appropriate Format. The output
attribute is required, others are optional (see the encoding.com documentation for full list of attributes).
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/encoding_dot_com/format.rb', line 10 def create(attributes) if attributes["output"] == "thumbnail" ThumbnailFormat.new(attributes) elsif attributes["output"] == "flv" && attributes["video_codec"] == "vp6" FLVVP6Format.new(attributes) elsif attributes["output"] == "image" ImageFormat.new(attributes) else VideoFormat.new(attributes) end end |
Instance Method Details
#build_xml(builder, destination_url = nil) ⇒ Object
Builds the XML for this format.
builder
-
a Nokogiri builder, declared with a block
destination_url
-
where the encoded file should be placed. See the encoding.com documentation for details.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/encoding_dot_com/format.rb', line 47 def build_xml(builder, destination_url=nil) logo_attributes, other_attributes = self.class.allowed_attributes.partition {|a| a[0..3] == "logo" } builder.format { builder.destination destination_url other_attributes.each do |attr| builder.send(attr, output_value(attr)) unless @attributes[attr].nil? end if logo_attributes.any? {|attr| @attributes[attr] } builder.logo { logo_attributes.each {|attr| builder.send(attr, output_value(attr)) if @attributes[attr] } } end } end |