Class: CineSync::ZoomState

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeZoomState

Returns a new instance of ZoomState.



5
6
7
8
# File 'lib/cinesync/zoom_state.rb', line 5

def initialize
  @center = [0.5, 0.5]
  @scale_factor = 1.0
end

Instance Attribute Details

#centerObject

Returns the value of attribute center.



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

def center
  @center
end

#scale_factorObject

Returns the value of attribute scale_factor.



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

def scale_factor
  @scale_factor
end

Class Method Details

.load(elem) ⇒ Object



267
268
269
270
271
272
273
274
# File 'lib/cinesync/xml.rb', line 267

def self.load(elem)
  returning self.new do |zs|
    x = elem.elements['center/attribute::x'].value.to_f
    y = elem.elements['center/attribute::y'].value.to_f
    zs.center = [x, y]
    zs.scale_factor = elem.elements['scaleFactor/attribute::value'].value.to_f
  end
end

Instance Method Details

#default?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/cinesync/zoom_state.rb', line 10

def default?
  center == [0.5, 0.5] and scale_factor == 1.0
end

#to_xml(x) ⇒ Object

eZoomState = element zoomState {

element center { aXY } &
eScaleFactor }


256
257
258
259
260
261
262
263
264
# File 'lib/cinesync/xml.rb', line 256

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

  x.zoomState {
    x.center(:x => center[0], :y => center[1])
    x.scaleFactor(:value => scale_factor)
  }
end

#valid?Boolean

Returns:

  • (Boolean)


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

def valid?
  default? or (center.length == 2 and center.all? {|p| (0.0..1.0) === p } and scale_factor > 0.0) rescue false
end