Class: CineSync::Mask
- Inherits:
-
Object
- Object
- CineSync::Mask
- Defined in:
- lib/cinesync/xml.rb,
lib/cinesync/mask.rb
Instance Attribute Summary collapse
-
#alpha ⇒ Object
Returns the value of attribute alpha.
-
#center ⇒ Object
Returns the value of attribute center.
-
#height ⇒ Object
Returns the value of attribute height.
-
#scale_factor ⇒ Object
Returns the value of attribute scale_factor.
-
#width ⇒ Object
Returns the value of attribute width.
Class Method Summary collapse
Instance Method Summary collapse
- #default? ⇒ Boolean
-
#initialize(ratio_or_width = nil, height = nil) ⇒ Mask
constructor
A new instance of Mask.
- #ratio ⇒ Object
- #ratio=(rat) ⇒ Object
-
#to_xml(x) ⇒ Object
eMask = element mask { aAlpha & element center { aXY } & element ratio { aRatio } & eScaleFactor }.
- #valid? ⇒ Boolean
Constructor Details
#initialize(ratio_or_width = nil, height = nil) ⇒ Mask
Returns a new instance of Mask.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/cinesync/mask.rb', line 6 def initialize(ratio_or_width = nil, height = nil) @alpha = 1.0 @center = [0.5, 0.5] @scale_factor = 1.0 if ratio_or_width and height.nil? self.ratio = ratio_or_width elsif ratio_or_width and height @width = Float(ratio_or_width) @height = Float(height) else @width = 1 @height = 1 end end |
Instance Attribute Details
#alpha ⇒ Object
Returns the value of attribute alpha.
3 4 5 |
# File 'lib/cinesync/mask.rb', line 3 def alpha @alpha end |
#center ⇒ Object
Returns the value of attribute center.
3 4 5 |
# File 'lib/cinesync/mask.rb', line 3 def center @center end |
#height ⇒ Object
Returns the value of attribute height.
4 5 6 |
# File 'lib/cinesync/mask.rb', line 4 def height @height end |
#scale_factor ⇒ Object
Returns the value of attribute scale_factor.
3 4 5 |
# File 'lib/cinesync/mask.rb', line 3 def scale_factor @scale_factor end |
#width ⇒ Object
Returns the value of attribute width.
4 5 6 |
# File 'lib/cinesync/mask.rb', line 4 def width @width end |
Class Method Details
.load(elem) ⇒ Object
326 327 328 329 330 331 332 333 334 335 336 |
# File 'lib/cinesync/xml.rb', line 326 def self.load(elem) returning self.new do |mask| mask.alpha = elem.attribute('alpha').value.to_f x = elem.elements['center/attribute::x'].value.to_f y = elem.elements['center/attribute::y'].value.to_f mask.center = [x, y] mask.width = elem.elements['ratio/attribute::width'].value.to_f mask.height = elem.elements['ratio/attribute::height'].value.to_f mask.scale_factor = elem.elements['scaleFactor/attribute::value'].value.to_f end end |
Instance Method Details
#default? ⇒ Boolean
31 32 33 34 |
# File 'lib/cinesync/mask.rb', line 31 def default? alpha == 1.0 and center == [0.5, 0.5] and scale_factor == 1.0 and width > 0.0 and width == height end |
#ratio ⇒ Object
21 22 23 24 25 |
# File 'lib/cinesync/mask.rb', line 21 def ratio wh = [width, height] # Convert to ints if the float represents an int wh.map {|f| (f == f.floor) ? f.to_i : f }.map {|num| num.to_s }.join(':') end |
#ratio=(rat) ⇒ Object
27 28 29 |
# File 'lib/cinesync/mask.rb', line 27 def ratio=(rat) @width, @height = rat.split(':', 2).map(&:to_f) end |
#to_xml(x) ⇒ Object
eMask = element mask {
aAlpha &
element center { aXY } &
element ratio { aRatio } &
eScaleFactor }
314 315 316 317 318 319 320 321 322 323 |
# File 'lib/cinesync/xml.rb', line 314 def to_xml(x) fail "#{self.inspect}: Invalid" unless valid? return if default? x.mask(:alpha => alpha) { x.center(:x => center[0], :y => center[1]) x.ratio(:width => width, :height => height) x.scaleFactor(:value => scale_factor) } end |
#valid? ⇒ Boolean
36 37 38 39 |
# File 'lib/cinesync/mask.rb', line 36 def valid? default? or (width > 0.0 and height > 0.0 and center.length == 2 and [alpha, scale_factor, *center].all? {|f| (0.0..1.0) === f }) rescue false end |