class MultimediaParadise::Video::VideoRenamer

Public Class Methods

[](i = ARGV) click to toggle source
#

MultimediaParadise::Video::VideoRenamer.new[]

#
# File lib/multimedia_paradise/video/video_renamer.rb, line 152
def self.[](i = ARGV)
  new(i)
end
new( i = ARGV, run_already = true ) click to toggle source
#

initialize

#
# File lib/multimedia_paradise/video/video_renamer.rb, line 30
def initialize(
    i           = ARGV,
    run_already = true
  )
  reset
  set_input(i)
  run if run_already
end

Public Instance Methods

all_titles?() click to toggle source
#

all_titles?

#
# File lib/multimedia_paradise/video/video_renamer.rb, line 73
def all_titles?
  dataset?.map {|key, hash|
    hash['title']
  }
end
dataset?() click to toggle source
#

dataset?

#
# File lib/multimedia_paradise/video/video_renamer.rb, line 66
def dataset?
  MultimediaParadise.return_all_video_files
end
first_word?() click to toggle source
#

first_word?

Obtain the first word of the input file.

#
# File lib/multimedia_paradise/video/video_renamer.rb, line 143
def first_word?
  _ = input?
  _ = _.split('_').first if _.include? '_'
  return _
end
input?() click to toggle source
#

input?

#
# File lib/multimedia_paradise/video/video_renamer.rb, line 59
def input?
  @input
end
rename_this_video_file(i = input?) click to toggle source
#

rename_this_video_file

Only call this method when you are sure that we have an input file.

It will then proceed to rename the video file.

#
# File lib/multimedia_paradise/video/video_renamer.rb, line 120
def rename_this_video_file(i = input?)
  matching_dataset = dataset?.select {|key, hash|
    downcased_word = first_word?.downcase
    hash['title'].downcase.include? downcased_word
  }
  if matching_dataset
    file_extension = File.extname(i).delete('.')
    the_key = matching_dataset.keys.first
    new_filename = the_key.to_s+'_'
    # ===================================================================== #
    # Next, append the real name.
    # ===================================================================== #
    new_filename << matching_dataset[the_key]['title'].delete(' ')+'.'+file_extension
    opnn; e 'Now renaming `'+sfile(input?)+'` to `'+sfile(new_filename)+'`.'
    rename_file(i, new_filename)
  end
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method MultimediaParadise::Base#reset
# File lib/multimedia_paradise/video/video_renamer.rb, line 42
def reset
  super()
  infer_the_namespace
end
run() click to toggle source
#

run (run tag)

#
# File lib/multimedia_paradise/video/video_renamer.rb, line 82
def run
  # ======================================================================= #
  # First, determine whether we have a match.
  # ======================================================================= #
  _ = first_word?
  # ======================================================================= #
  # If a '.' is there, we will assume a file extension such as '.mp4'
  # which is not necessary, thus it will be removed..
  # ======================================================================= #
  if _.include? '.'
    _.sub!(/#{File.extname(_)}$/,'')
  end
  video_is_registered = all_titles?.any? {|entry|
    entry.include? _
  }
  if video_is_registered
    rename_this_video_file
  else
    opnn; e 'It appears as if we do not have a video for this '\
            'input ('+simp(_)+').'
    # ===================================================================== #
    # === Check for numbers only
    # ===================================================================== #
    if _.to_s =~ /^\d+$/
      title = dataset?[_.to_i]['title']
      e 'Only numbers were given. We will thus check for the given file'
      e 'position at number '+simp(_)+' which is `'+simp(title)+'`.'
    end
  end
end
set_input(i = '') click to toggle source
#

set_input

#
# File lib/multimedia_paradise/video/video_renamer.rb, line 50
def set_input(i = '')
  i = i.first if i.is_a? Array
  i = i.to_s.dup
  @input = i
end