class MultimediaParadise::GuessVideoName
Constants
- NAMESPACE
#¶ ↑
NAMESPACE
¶ ↑#¶ ↑
Public Class Methods
[](i = '')
click to toggle source
Public Instance Methods
determine_possible_matches()
click to toggle source
#¶ ↑
determine_possible_matches
¶ ↑
#¶ ↑
# File lib/multimedia_paradise/video/guess_video_name.rb, line 85 def determine_possible_matches simpler_input = @original_input.downcase.delete(' ') available_video_titles = return_array_all_available_video_titles possible_titles = available_video_titles.map {|entry| entry.downcase.delete(' ') } selection = possible_titles.select {|long_video_name| long_video_name.include? simpler_input } if selection.empty? opnn; e 'We could not find any result for `'+sfancy(original_input?)+'`.' else opnn; e 'At the least one result was found for the input `'+ sfancy(original_input?)+'`.' opnn; e 'We will next display these results:' pp selection # ===================================================================== # # Here, we will show these results again. # ===================================================================== # fine_tuned_selection = available_video_titles.select {|inner_entry| inner_entry.downcase.delete(' ').include? simpler_input } # ===================================================================== # # Next, we will re-arrange the array a bit. We will favour entries # that have a beginning and a trailing '_' character. This should # sort it, but I am not 100% sure if it is correct. # ===================================================================== # sanitized_selection = fine_tuned_selection.sort_by {|line| result = (line =~ / #{@original_input} /) result = -1 if result.nil? result }.reverse if sanitized_selection.size > 1 opnn; e 'More than one entry was found. We will use the first entry only.' sanitized_selection = sanitized_selection.first end if sanitized_selection.is_a? Array sanitized_selection = sanitized_selection.first end opnn; e 'Assuming the filename may be '+sfile(sanitized_selection) e sfancy(' '+sanitized_selection) # ===================================================================== # # The next step requires that we have found the right title. # ===================================================================== # number = determine_the_number_from_this_title( sanitized_selection ) opnn; e 'The number may be `'+sfancy(number)+'`.' opnn; e 'Provided that the above information is correct, we '\ 'suggest this name:' new_name_suggestion = number+'_'+sanitized_selection.delete(' ') e e sfancy(' '+new_name_suggestion) e opnn; e 'With popular file extensions, it may be:' e e sfancy(' '+new_name_suggestion+'.mp4') e sfancy(' '+new_name_suggestion+'.avi') e end end
determine_the_number_from_this_title(title)
click to toggle source
#¶ ↑
determine_the_number_from_this_title
¶ ↑
The number that is to be returned by this method shall be padded with ‘0’ if it is below 1000.
#¶ ↑
# File lib/multimedia_paradise/video/guess_video_name.rb, line 153 def determine_the_number_from_this_title(title) number = '0' title = ensure_main_encoding(title) hash_containing_only_the_numbers_and_titles = {} @video_dataset.each_pair {|inner_number, hash_values| inner_title = ensure_main_encoding(hash_values['title']) hash_containing_only_the_numbers_and_titles[inner_title] = ensure_main_encoding( inner_number.to_s.rjust(3,'0') ) } if hash_containing_only_the_numbers_and_titles.has_key?(title) number = hash_containing_only_the_numbers_and_titles[title] else opnn; e 'No entry for '+sfancy(title)+' could be found.' end number end
original_input?()
click to toggle source
reset()
click to toggle source
#¶ ↑
reset (reset tag)¶ ↑
#¶ ↑
Calls superclass method
MultimediaParadise::Base#reset
# File lib/multimedia_paradise/video/guess_video_name.rb, line 38 def reset super() _ = file_video_collection? if File.exist? _ @video_dataset = YAML.load_file(_) else opnn; e 'No file at '+sfile(_)+' exists.' end # ======================================================================= # # === @namespace # ======================================================================= # @namespace = NAMESPACE end
return_array_all_available_video_titles()
click to toggle source
#¶ ↑
return_array_all_available_video_titles
¶ ↑
This method will return an Array holding all registered video titles. Note
that this method will also ensure that the main encoding in use, is actually used.
#¶ ↑
# File lib/multimedia_paradise/video/guess_video_name.rb, line 59 def return_array_all_available_video_titles array = @video_dataset.values.map {|hash| ensure_main_encoding(hash['title']) }.flatten return array end
Also aliased as: array_all_available_video_titles
run()
click to toggle source