class MovieMasher::Source
A Transfer
object used for Input#source
and Media#source, describing how to retrieve an audio, image, video or mash JSON/YML file.
When building file paths, components will automatically have slashes inserted between them as needed so trailing and leading slashes are optional. The extension
will be populated and removed from name
if it exists there. # user:pass@example.com:444/media/video.mp4 Source.create
{ type: Type::HTTPS, user: 'user', pass: 'pass', host: 'example.com', port: 444, path: 'media/video.mp4' }
Public Class Methods
create(hash = nil)
click to toggle source
create_if(hash)
click to toggle source
# File lib/source.rb, line 26 def self.create_if(hash) (hash ? create(hash) : nil) end
init_hash(hash = nil)
click to toggle source
# File lib/source.rb, line 30 def self.init_hash(hash = nil) hash ||= {} Hashable._init_key hash, :type, Type::FILE case hash[:type] when Type::FILE Hashable._init_key hash, :method, Method::SYMLINK when Type::HTTP Hashable._init_key hash, :method, Method::GET end Transfer.init_hash(hash) end
init_string(url)
click to toggle source
# File lib/source.rb, line 42 def self.init_string(url) hash = {} uri = URI url hash[:type] = uri.scheme if uri.scheme #=> "http(s)" hash[:host] = uri.host if uri.host #=> "foo.com" hash[:path] = uri.path #=> "/posts" hash[:user] = uri.user if uri.user hash[:pass] = uri.password if uri.password hash[:port] = uri.port if uri.port hash[:parameters] = CGI.parse(uri.query) if uri.query hash end
new(hash_or_string = nil)
click to toggle source
Calls superclass method
# File lib/source.rb, line 64 def initialize(hash_or_string = nil) if hash_or_string.is_a?(String) hash_or_string = self.class.init_string(hash_or_string) end self.class.init_hash hash_or_string super hash_or_string end
Public Instance Methods
extension()
click to toggle source
# File lib/source.rb, line 55 def extension _get __method__ end
extension=(value)
click to toggle source
- String
-
Appended to file path after
name
, with period inserted between.
# File lib/source.rb, line 60 def extension=(value) _set __method__, value end
name()
click to toggle source
# File lib/source.rb, line 72 def name _get __method__ end
name=(value)
click to toggle source
- String
-
The full or basename of file appended to file path. If full,
extension
will be set and removed from value.
# File lib/source.rb, line 78 def name=(value) _set __method__, value end