class IML::Base

Base media file class

Attributes

format_string[RW]

@return <String> Allows retrieving and setting of the format string for the output name

prefix[RW]

@return <String> Allows for setting and getting the output path sans the output base filename

pretend[RW]

@return <Boolean> Allows for setting and getting dry run setting

Public Class Methods

new(hash = nil, options = {}) click to toggle source
Calls superclass method
# File lib/iml/base.rb, line 15
def initialize(hash = nil, options = {})
  @prefix = options[:target]
  @pretend = options[:pretend]
  super(hash)
  process if hash
end

Public Instance Methods

create_dir() click to toggle source

Creates the output directory if needed @return [Array<String>] array containing the path of the created output directory @example

movie = IML::Text.new('Cool.Movie.2018.720p.BluRay.H264.AAC2.0-GROUP.mp4').detect
# => <IML::Movie title="Cool Movie", year="2018", quality="720p", source="BluRay" ..>
movie.create_dir
# => ["."]
# File lib/iml/base.rb, line 43
def create_dir
  FileUtils.mkdir_p dirname unless @pretend
end
move(path) click to toggle source

Moves the media file to the output directory @return <Integer> 0 on success, 1 on failure

# File lib/iml/base.rb, line 49
def move(path)
  FileUtils.mv path, pathname unless @pretend
rescue Errno::ENOENT
  1
end
pathname() click to toggle source

@return [Pathname] full output path of the media file

# File lib/iml/base.rb, line 32
def pathname
  @prefix ? Pathname(@prefix) + Pathname(present) : Pathname(present)
end
present() click to toggle source

@return [String] formated output filename

# File lib/iml/base.rb, line 23
def present
  format_string = output_format
  self.class::PLACEHOLDERS.each do |placeholder, attribute|
    format_string = format_string.gsub(placeholder, send(attribute).to_s)
  end
  format_string
end

Private Instance Methods

delete_fields() click to toggle source
# File lib/iml/base.rb, line 83
def delete_fields
  each_pair do |k, v|
    delete_field(k) unless v
  end
end
final_audio_format?() click to toggle source
# File lib/iml/base.rb, line 79
def final_audio_format?
  return true if IML::Patterns.config.audio.values.map { |a| a[:name] }.include?(audio) || !audio
end
normalize_audio_codec_name() click to toggle source
# File lib/iml/base.rb, line 73
def normalize_audio_codec_name
  return false if final_audio_format?
  self.channels = IML::Patterns.config.audio[audio.downcase][:channels]
  self.audio = IML::Patterns.config.audio[audio.downcase][:name]
end
normalize_video_codec_name() click to toggle source
# File lib/iml/base.rb, line 69
def normalize_video_codec_name
  self.codec = IML::Patterns.config.codec[codec.downcase] unless IML::Patterns.config.codec.value?(codec.downcase)
end
output_format() click to toggle source
# File lib/iml/base.rb, line 57
def output_format
  format_string || self.class::DEFAULT_FORMAT
end
process() click to toggle source

Process the IML::Base object and apply some normalizing and cleanup on the fields

# File lib/iml/base.rb, line 62
def process
  normalize_video_codec_name if codec
  normalize_audio_codec_name if audio
  titleize
  delete_fields
end
titleize() click to toggle source
# File lib/iml/base.rb, line 89
def titleize
  self.title = IML::Text.new(title).to_title if title.is_a?(String)
  self.episode_title = IML::Text.new(episode_title).to_title if episode_title.is_a?(String)
  self.episode_title = nil if episode_title.to_s.empty?
end