Class: CineSync::Session
- Inherits:
-
Object
- Object
- CineSync::Session
- Defined in:
- lib/cinesync/xml.rb,
lib/cinesync/session.rb
Instance Attribute Summary collapse
-
#chat_elem ⇒ Object
Returns the value of attribute chat_elem.
-
#file_version ⇒ Object
readonly
Returns the value of attribute file_version.
-
#groups ⇒ Object
Returns the value of attribute groups.
-
#media ⇒ Object
Returns the value of attribute media.
-
#notes ⇒ Object
Returns the value of attribute notes.
-
#stereo_elem ⇒ Object
Returns the value of attribute stereo_elem.
-
#user_data ⇒ Object
Returns the value of attribute user_data.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Session
constructor
A new instance of Session.
- #session_features ⇒ Object
-
#to_xml ⇒ Object
eSession = element session { attribute version { xsd:integer { minInclusive = “3” } } & attribute sessionFeatures { “standard” | “pro” } & aUserData? & eGroup* & eNotes? & eChat? & eMedia* }.
- #valid? ⇒ Boolean
Constructor Details
#initialize ⇒ Session
Returns a new instance of Session.
7 8 9 10 11 12 13 |
# File 'lib/cinesync/session.rb', line 7 def initialize @file_version = SessionV3XMLFileVersion @user_data = '' @media = [] @groups = [] @notes = '' end |
Instance Attribute Details
#chat_elem ⇒ Object
Returns the value of attribute chat_elem.
5 6 7 |
# File 'lib/cinesync/session.rb', line 5 def chat_elem @chat_elem end |
#file_version ⇒ Object (readonly)
Returns the value of attribute file_version.
3 4 5 |
# File 'lib/cinesync/session.rb', line 3 def file_version @file_version end |
#groups ⇒ Object
Returns the value of attribute groups.
4 5 6 |
# File 'lib/cinesync/session.rb', line 4 def groups @groups end |
#media ⇒ Object
Returns the value of attribute media.
4 5 6 |
# File 'lib/cinesync/session.rb', line 4 def media @media end |
#notes ⇒ Object
Returns the value of attribute notes.
4 5 6 |
# File 'lib/cinesync/session.rb', line 4 def notes @notes end |
#stereo_elem ⇒ Object
Returns the value of attribute stereo_elem.
5 6 7 |
# File 'lib/cinesync/session.rb', line 5 def stereo_elem @stereo_elem end |
#user_data ⇒ Object
Returns the value of attribute user_data.
4 5 6 |
# File 'lib/cinesync/session.rb', line 4 def user_data @user_data end |
Class Method Details
.load(str_or_io, silent = false) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/cinesync/xml.rb', line 43 def self.load(str_or_io, silent = false) doc = REXML::Document.new(str_or_io) # Do a few checks (the user should have already confirmed that the # document conforms to the schema, but we'll try to fail early in case) fail 'Expected to find root <session> element' unless doc.root.name == 'session' fail %Q[Root <session> element must have attribute xmlns="#{SessionV3Namespace}"] unless doc.root.attribute('xmlns').value == SessionV3Namespace doc_version = doc.root.attribute('version').value.to_i if doc_version > SessionV3XMLFileVersion $stderr.puts("Warning: Loading session file with a newer version (#{doc_version}) than this library (#{SessionV3XMLFileVersion})") unless silent end elem = doc.root returning self.new do |s| s.instance_variable_set(:@file_version, doc_version) s.user_data = elem.attribute('userData').andand.value || '' s.groups = elem.get_elements('group').map {|g_elem| g_elem.text } s.notes = elem.elements['notes'].andand.text || '' s.chat_elem = elem.get_elements('chat').andand[0] s.stereo_elem = elem.get_elements('stereo').andand[0] s.media = elem.get_elements('media').map {|e| MediaBase.load(e) } end end |
Instance Method Details
#session_features ⇒ Object
15 16 17 |
# File 'lib/cinesync/session.rb', line 15 def session_features (stereo_elem or media.any? {|m| m.uses_pro_features? }) ? :pro : :standard end |
#to_xml ⇒ Object
eSession = element session {
attribute version { xsd:integer { minInclusive = "3" } } &
attribute sessionFeatures { "standard" | "pro" } &
aUserData? &
eGroup* &
eNotes? &
eChat? &
eMedia* }
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/cinesync/xml.rb', line 20 def to_xml fail "#{self.inspect}: Invalid" unless valid? x = Builder::XmlMarkup.new(:indent => 4) x.instruct! attrs = {} attrs['xmlns'] = SessionV3Namespace # Always write as the version we know, not the version we loaded attrs['version'] = SessionV3XMLFileVersion attrs['sessionFeatures'] = session_features attrs['userData'] = user_data unless user_data.empty? x.session(attrs) { groups.each {|g| x.group(g) } x.notes(notes) unless notes.empty? x << chat_elem.to_s if chat_elem x << stereo_elem.to_s if stereo_elem media.each {|m| m.to_xml(x) } } end |
#valid? ⇒ Boolean
19 20 21 22 |
# File 'lib/cinesync/session.rb', line 19 def valid? file_version == SessionV3XMLFileVersion and media.all? {|m| m.valid? } end |