Class: CineSync::FrameAnnotation

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

Constant Summary collapse

DrawingObjectElements =

eFrameAnnotation = element annotation {

attribute frame { tFrameNumber } &
eNotes? &
eObject* }
%w(line erase circle arrow text)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(frame_num) ⇒ FrameAnnotation

Returns a new instance of FrameAnnotation.



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

def initialize(frame_num)
  @frame = frame_num
  @notes = ''
  @drawing_objects = []
end

Instance Attribute Details

#drawing_objectsObject

Returns the value of attribute drawing_objects.



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

def drawing_objects
  @drawing_objects
end

#frameObject

Returns the value of attribute frame.



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

def frame
  @frame
end

#notesObject

Returns the value of attribute notes.



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

def notes
  @notes
end

Class Method Details

.load(elem) ⇒ Object



426
427
428
429
430
431
432
433
# File 'lib/cinesync/xml.rb', line 426

def self.load(elem)
  returning self.new(elem.attribute('frame').value.to_i) do |ann|
    ann.notes = elem.elements['notes'].andand.text || ''
    DrawingObjectElements.each do |obj_name|
      ann.drawing_objects += elem.get_elements(obj_name)
    end
  end
end

Instance Method Details

#default?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/cinesync/frame_annotation.rb', line 11

def default?
  notes.empty? and drawing_objects.empty?
end

#to_xml(x) ⇒ Object



412
413
414
415
416
417
418
419
420
421
422
423
# File 'lib/cinesync/xml.rb', line 412

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

  attrs = {}
  attrs['frame'] = frame

  x.annotation(attrs) {
    x.notes(notes) unless notes.empty?
    drawing_objects.each {|obj| x << obj.to_s }
  }
end

#valid?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/cinesync/frame_annotation.rb', line 15

def valid?
  frame >= 1 rescue false
end