class MultimediaParadise::VideoGenres
Constants
- NAMESPACE
#¶ ↑
NAMESPACE
¶ ↑#¶ ↑
Public Class Methods
[](i = '')
click to toggle source
Public Instance Methods
display_these_entries(i)
click to toggle source
#¶ ↑
display_these_entries
¶ ↑
This method will report the given input, which should be a Hash - a Hash containing the video files.
#¶ ↑
# File lib/multimedia_paradise/video/video_genres.rb, line 190 def display_these_entries(i) if i.is_a?(Hash) and !i.empty? n_entries = i.keys.size result = 'Displaying the following '+ sfancy(n_entries.to_s+' entries').dup+' next' opnn; e result result = ''.dup if @search_for_this_genre result << 'for the genre '+simp(@search_for_this_genre) end result << ':' opnn; e result e i.each_pair {|position, hash_dataset_including_the_title| title = hash_dataset_including_the_title['title'] e simp(title.ljust(40))+ ' (at position '+ springgreen(position.to_s.rjust(3))+')' } e end end
do_search_for_this_genre(i)
click to toggle source
#¶ ↑
do_search_for_this_genre
¶ ↑
This is the action-method that allows you tos earch for a specific genre in our yaml dataset.
Invocation examples:
video_genres --genre="Science Fiction" video_genres --genre="eastern" video_genres --genre="horror" video_genres --genre=horror video_genres --science-fiction
#¶ ↑
# File lib/multimedia_paradise/video/video_genres.rb, line 292 def do_search_for_this_genre(i) search_for_this_genre = i.to_s.dup set_search_for_this_genre(search_for_this_genre) _ = file_video_collection? if File.exist? _ opnn; e "Selecting all genres fitting the search term `"\ "#{simp(@search_for_this_genre)}`." dataset = YAML.load_file(_) selection = dataset.select {|key, hash_value| if hash_value and hash_value.has_key?('genre') genre_entry = hash_value['genre'] if genre_entry genre_entry.downcase.delete(' ').include?(@search_for_this_genre.downcase.delete(' ')) else opnn; e "Warning: key #{key} has no genre tag." false end else false end } display_these_entries(selection) else opnn; e "No file called #{sfile(_)} could be found." end end
input?()
click to toggle source
main_yaml_file?()
click to toggle source
play_a_random_video_from( this_genre )
click to toggle source
#¶ ↑
play_a_random_video_from
¶ ↑
Use this method if you wish to play a random video from a given genre. The genre must exist, of course - and so must the file that you wish to play.
The first argument to this method determines the genre in use.
To invoke this, try:
video_genres --play-random-video-from-this-genre=horror
#¶ ↑
# File lib/multimedia_paradise/video/video_genres.rb, line 227 def play_a_random_video_from( this_genre ) set_search_for_this_genre(this_genre) dataset = YAML.load_file(main_yaml_file?) selection = dataset.select {|key, hash_value| if hash_value and hash_value.has_key?('genre') genre_entry = hash_value['genre'] if genre_entry search_term = @search_for_this_genre.downcase.delete(' _') genre_entry.downcase.delete(' _').include?(search_term) end else false end } # ======================================================================= # # Now we need to pick a random key. # ======================================================================= # play_for_this_key = selection.keys.sample.to_s.rjust(3,'0') target = "#{DEPOT_VIDEO}Realvids/#{play_for_this_key}*" location = Dir[target] if location.is_a? Array play_this_file = location.first end if play_this_file if File.exist?(play_this_file) opnn; e "Now playing the videofile `#{sfile(play_this_file)}`." play_this_video_file(play_this_file) else opnn; e 'No file was found at `'+sfile(play_this_file)+'`.' end else opnn; e 'No result found for `'+sfancy(target)+'`.' pp selection[play_for_this_key.to_i] end end
play_this_video_file(i)
click to toggle source
reset()
click to toggle source
#¶ ↑
reset (reset tag)¶ ↑
#¶ ↑
Calls superclass method
MultimediaParadise::Base#reset
# File lib/multimedia_paradise/video/video_genres.rb, line 50 def reset super() # ======================================================================= # # === @namespace # ======================================================================= # @namespace = NAMESPACE # ======================================================================= # # === @search_for_this_genre # ======================================================================= # @search_for_this_genre = nil end
run()
click to toggle source
set_input(i = '')
click to toggle source
#¶ ↑
set_input
¶ ↑
#¶ ↑
# File lib/multimedia_paradise/video/video_genres.rb, line 65 def set_input(i = '') i = i.first if i.is_a? Array i = i.to_s.dup # ======================================================================= # # Do a bit of sanitizing next: # ======================================================================= # case i # case tag # ======================================================================= # # === video_genres --science-fiction # ======================================================================= # when /^-?-?science(-| |_)?fiction$/ i = '--genre="Science Fiction"' end @input = i end
set_search_for_this_genre(i)
click to toggle source
show_available_genres()
click to toggle source
#¶ ↑
show_available_genres
(available tag)¶ ↑
This method will show the available genres. For this it will tap into the .yml file and simply colllect all genres into an Array.
Invocation example:
video_genres --available_genres
#¶ ↑
# File lib/multimedia_paradise/video/video_genres.rb, line 160 def show_available_genres _ = main_yaml_file? hash = YAML.load_file(_) array = [] hash.each_pair {|key, value_hash| if value_hash.has_key? 'genre' genre = value_hash['genre'] array << genre end } array.sort! array.uniq! opnn; e 'These '+sfancy(array.size.to_s)+' genres are available:' array.each {|this_genre| e sfancy(" #{this_genre}") } end
show_help()
click to toggle source