Class: CineSync::PixelRatio

Inherits:
Object
  • Object
show all
Defined in:
lib/cinesync/xml.rb,
lib/cinesync/pixel_ratio.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePixelRatio

Returns a new instance of PixelRatio.



6
7
8
9
10
11
# File 'lib/cinesync/pixel_ratio.rb', line 6

def initialize
  @source_width  = 1.0
  @source_height = 1.0
  @target_width  = 1.0
  @target_height = 1.0
end

Instance Attribute Details

#source_heightObject

Returns the value of attribute source_height.



3
4
5
# File 'lib/cinesync/pixel_ratio.rb', line 3

def source_height
  @source_height
end

#source_widthObject

Returns the value of attribute source_width.



3
4
5
# File 'lib/cinesync/pixel_ratio.rb', line 3

def source_width
  @source_width
end

#target_heightObject

Returns the value of attribute target_height.



4
5
6
# File 'lib/cinesync/pixel_ratio.rb', line 4

def target_height
  @target_height
end

#target_widthObject

Returns the value of attribute target_width.



4
5
6
# File 'lib/cinesync/pixel_ratio.rb', line 4

def target_width
  @target_width
end

Class Method Details

.load(elem) ⇒ Object



296
297
298
299
300
301
302
303
# File 'lib/cinesync/xml.rb', line 296

def self.load(elem)
  returning self.new do |pr|
    pr.source_width  = elem.elements['source/attribute::width'].value.to_f
    pr.source_height = elem.elements['source/attribute::height'].value.to_f
    pr.target_width  = elem.elements['target/attribute::width'].value.to_f
    pr.target_height = elem.elements['target/attribute::height'].value.to_f
  end
end

Instance Method Details

#default?Boolean

Returns:

  • (Boolean)


13
14
15
16
# File 'lib/cinesync/pixel_ratio.rb', line 13

def default?
  source_width > 0.0 and source_width == source_height and
  target_width > 0.0 and target_width == target_height
end

#to_xml(x) ⇒ Object

ePixelRatio = element pixelRatio {

element source { aRatio } &
element target { aRatio } }

aRatio &= attribute width { tPositiveFloat } aRatio &= attribute height { tPositiveFloat }



285
286
287
288
289
290
291
292
293
# File 'lib/cinesync/xml.rb', line 285

def to_xml(x)
  fail "#{self.inspect}: Invalid" unless valid?
  return if default?

  x.pixelRatio {
    x.source(:width => source_width, :height => source_height)
    x.target(:width => target_width, :height => target_height)
  }
end

#valid?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/cinesync/pixel_ratio.rb', line 18

def valid?
  default? or ([source_width, source_height, target_width, target_height].all? {|x| x > 0.0 }) rescue false
end