Skip to content

Commit

Permalink
Fix framerate and par configuration through hashes
Browse files Browse the repository at this point in the history
  • Loading branch information
cassiomarques committed Jul 8, 2011
1 parent afe4edb commit 97f0566
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/uencode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def configure

module AttrSetting
def set_attributes(options)
self.class.const_get("ATTRIBUTES").each { |attr| instance_variable_set(:"@#{attr}", options[attr]) }
self.class.const_get("ATTRIBUTES").each { |attr| instance_variable_set(:"@#{attr}", options[attr.to_sym] || options[attr.to_s]) }
end

def initialize(options)
Expand Down
22 changes: 19 additions & 3 deletions lib/uencode/elements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def to_xml
end

module RateElement
ATTRIBUTES = [:numerator, :denominator]

include AttrSetting

def to_xml
%Q{
<#{root_name}>
Expand All @@ -36,19 +40,21 @@ def to_xml
</#{root_name}>
}
end

def ==(other)
numerator == other.numerator && denominator == other.denominator
end
end

class FrameRate
include RateElement
ATTRIBUTES = [:numerator, :denominator]

private
def root_name; "framerate"; end
end

class Par < FrameRate
include RateElement
ATTRIBUTES = [:numerator, :denominator]

private
def root_name; "par"; end
Expand Down Expand Up @@ -203,6 +209,16 @@ def initialize
@passes = 1
@stretch = false
end

def framerate=(_framerate)
_framerate = FrameRate.new(_framerate) unless _framerate.instance_of?(FrameRate) || _framerate.nil?
instance_variable_set :@framerate, _framerate
end

def par=(_par)
_par = Par.new(_par) unless _par.instance_of?(Par) || _par.nil?
instance_variable_set :@par, _par
end
end

# The audio configs for each Medium
Expand Down Expand Up @@ -262,5 +278,5 @@ def to_xml
end
end

[Size, FrameRate, Crop, VideoOutput, CaptureOutput, Job].each { |klass| klass.send :include, AttrSetting }
[Size, Crop, VideoOutput, CaptureOutput, Job].each { |klass| klass.send :include, AttrSetting }
end
27 changes: 24 additions & 3 deletions spec/elements_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,20 @@
it { medium.video.width.should == 400 }

context "from a hash (video parameters)" do
before { medium.configure config }
subject { medium.video_config }

before { medium.configure config }

its(:bitrate) { should == video_config["bitrate"] }
its(:codec) { should == video_config["codec"] }
its(:cbr) { should == video_config["cbr"] }
its(:crop) { should == video_config["crop"] }
its(:deinterlace) { should == video_config["deinterlace"] }
its(:framerate) { should == video_config["framerate"] }
its(:framerate) { should == UEncode::FrameRate.new(video_config["framerate"]) }
its(:height) { should == video_config["height"] }
its(:keyframe_interval) { should == video_config["keyframe_interval"] }
its(:maxbitrate) { should == video_config["maxbitrate"] }
its(:par) { should == video_config["par"] }
its(:par) { should == UEncode::Par.new(video_config["par"]) }
its(:profile) { should == video_config["profile"] }
its(:passes) { should == video_config["passes"] }
its(:stretch) { should == video_config["stretch"] }
Expand Down Expand Up @@ -361,6 +362,26 @@
end
end

describe UEncode::VideoConfig do
let(:config) { described_class.new }

context "receiving a hash as the framerate" do
before { config.framerate = {:numerator => 123, :denominator => 345} }

it "converts it to a UEncode::FrameRate" do
config.framerate.should be_an_instance_of(UEncode::FrameRate)
end

it "the framerate has the correct numerator" do
config.framerate.numerator.should == 123
end

it "the framerate has the correct denominator" do
config.framerate.denominator.should == 345
end
end
end

describe UEncode::FrameRate do
let(:name) { "framerate" }
let(:numerator) { 1000 }
Expand Down

0 comments on commit 97f0566

Please sign in to comment.