Class: CineSync::MediaLocator
- Inherits:
-
Object
- Object
- CineSync::MediaLocator
- Defined in:
- lib/cinesync/xml.rb,
lib/cinesync/media_file.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
Returns the value of attribute path.
-
#short_hash ⇒ Object
Returns the value of attribute short_hash.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(path_or_url_or_hash = nil) ⇒ MediaLocator
constructor
A new instance of MediaLocator.
-
#to_xml(x) ⇒ Object
eLocator |= element path { tFilePath } eLocator |= element shortHash { tShortHash } eLocator |= element url { tURL }.
- #valid? ⇒ Boolean
Constructor Details
#initialize(path_or_url_or_hash = nil) ⇒ MediaLocator
Returns a new instance of MediaLocator.
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/cinesync/media_file.rb', line 93 def initialize(path_or_url_or_hash = nil) @path = nil @url = nil @short_hash = nil s = String(path_or_url_or_hash) unless s.empty? maybe_uri = URI::parse(s) rescue nil if File.exist? s @path = File.(s) @short_hash = CineSync::short_hash(@path) elsif maybe_uri and maybe_uri.scheme # The argument could be parsed as a URI (use it as a URL) @url = maybe_uri elsif s =~ /^[0-9a-f]{40}$/ # Length is 40 characters and consists of all hex digits; assume this is a short hash @short_hash = s else # Finally, assume it's a file path if s =~ /^[A-Z]:[\\\/]/ # Looks like an absolute DOS path; let it through @path = s else @path = File.(s) end end end end |
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
91 92 93 |
# File 'lib/cinesync/media_file.rb', line 91 def path @path end |
#short_hash ⇒ Object
Returns the value of attribute short_hash.
91 92 93 |
# File 'lib/cinesync/media_file.rb', line 91 def short_hash @short_hash end |
#url ⇒ Object
Returns the value of attribute url.
91 92 93 |
# File 'lib/cinesync/media_file.rb', line 91 def url @url end |
Class Method Details
.load(elem) ⇒ Object
211 212 213 214 215 216 217 218 219 |
# File 'lib/cinesync/xml.rb', line 211 def self.load(elem) returning self.new do |loc| loc.path = elem.elements['path'].andand.text loc.short_hash = elem.elements['shortHash'].andand.text if elem.elements['url'] loc.url = URI::parse(elem.elements['url'].text) end end end |
Instance Method Details
#to_xml(x) ⇒ Object
eLocator |= element path { tFilePath } eLocator |= element shortHash { tShortHash } eLocator |= element url { tURL }
200 201 202 203 204 205 206 207 208 |
# File 'lib/cinesync/xml.rb', line 200 def to_xml(x) fail "#{self.inspect}: Invalid" unless valid? x.locators { x.path(path) if path x.shortHash(short_hash) if short_hash x.url(String(url)) if url } end |
#valid? ⇒ Boolean
123 124 125 |
# File 'lib/cinesync/media_file.rb', line 123 def valid? path or url or short_hash end |