class MovieMasher::Source

A Transfer object used for MovieMasher::Asset#source and Media#source, describing how toretrieve an audio, image, video or mash JSON/YML file.

When building file paths, components will automatically have slashesinserted between them as needed so trailing and leading slashes areoptional. The extension will be populated and removed from name if itexists there.# user:pass@example.com:444/media/video.mp4Source.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

Returns a new instance.

# File lib/source.rb, line 21
def self.create(hash = nil)
  (hash.is_a?(Source) ? hash : Source.new(hash))
end
create_if(hash) click to toggle source
# File lib/source.rb, line 24
def self.create_if(hash)
  (hash ? create(hash) : nil)
end
init_hash(hash = nil) click to toggle source
# File lib/source.rb, line 27
def self.init_hash(hash = nil)
  hash = {} unless 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 38
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 57
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 50
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 54
def extension=(value)
  _set __method__, value
end
name() click to toggle source
# File lib/source.rb, line 64
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 69
def name=(value)
  _set __method__, value
end