class MultimediaParadise::Video::MovieSearcher
Constants
- API_KEY
- NAMESPACE
#¶ ↑
NAMESPACE
¶ ↑#¶ ↑
Public Class Methods
[](i = '')
click to toggle source
Public Instance Methods
api_key?()
click to toggle source
cliner(optional_input = nil)
click to toggle source
#¶ ↑
cliner¶ ↑
If input is provided, then we will use this embedded into the line.
#¶ ↑
# File lib/multimedia_paradise/video/movie_searcher.rb, line 152 def cliner(optional_input = nil) result = '=' * @width_limit if optional_input _ = " #{optional_input} " # ===================================================================== # # Also colourize the title there. # ===================================================================== # result[1,_.size] = palegoldenrod(_) end return result+N end
display_main_string()
click to toggle source
name_of_the_movie?()
click to toggle source
#¶ ↑
name_of_the_movie?¶ ↑
#¶ ↑
# File lib/multimedia_paradise/video/movie_searcher.rb, line 116 def name_of_the_movie? @name_of_the_movie end
Also aliased as: movie_name?
report_that_no_movie_has_been_found_with_this_name( i = movie_name? )
click to toggle source
reset()
click to toggle source
#¶ ↑
reset (reset tag)¶ ↑
#¶ ↑
Calls superclass method
MultimediaParadise::Base#reset
# File lib/multimedia_paradise/video/movie_searcher.rb, line 65 def reset super() # ======================================================================= # # === @namespace # ======================================================================= # @namespace = NAMESPACE # ======================================================================= # # === @width_limit # ======================================================================= # @width_limit = 78 # ======================================================================= # # === @main_string # ======================================================================= # @main_string = ''.dup # ======================================================================= # # === @api_key # ======================================================================= # @api_key = API_KEY end
run()
click to toggle source
#¶ ↑
run (run tag)¶ ↑
#¶ ↑
# File lib/multimedia_paradise/video/movie_searcher.rb, line 197 def run determine_whether_rest_client_is_available_and_exit_if_it_is_unavailable # ======================================================================= # # First, denote the names to end the program early. # ======================================================================= # _ = movie_name? # Pointer to the movie name. case _ # case tag when 'quit','exit' exit 0 else url = "http://www.omdbapi.com/?t=#{_}&apikey=#{api_key?}" if debug? opnn; e 'Now working on the URL `'+sfancy(url)+'`.' end # ===================================================================== # # The constructed URl would look like this: # http://www.omdbapi.com/?t=Alien&apikey=946f500a # ===================================================================== # response = RestClient.get(url) # ===================================================================== # # Next, parse the response via JSON. # ===================================================================== # info = JSON.parse(response) # ===================================================================== # # Handle exceptions, in case that we obtain an invalid response. # ===================================================================== # case info['Response'].to_s when 'False' report_that_no_movie_has_been_found_with_this_name(_) exit 0 else # =================================================================== # # We have to rescue in the event that no tomato score has been # supplied. Additionally, we will word wrap to the plot content # and the actors of said movie. # # Commandline examples: # # commandline_imdb Toy Story # # =================================================================== # begin title = info['Title'] year = info['Year'] score = info['Ratings'][1]['Value'] rescue score = 'No Score Found' end indent_to_use = 65 rated = info['Rated'] genre = info['Genre'] director = info['Director'] actors = wrap(info['Actors'], indent_to_use) plot_unformatted = info['Plot'] plot = wrap(plot_unformatted, indent_to_use) @main_string << "#{N}" << cliner('Movie') @main_string << "| #{mediumorchid('Title')}: #{title}"+N @main_string << "| #{mediumpurple('Year')}: #{year.rjust(5)}"+N @main_string << "| #{skyblue('Tomato')}: #{score.rjust(5)}"+N @main_string << "| #{royalblue('Rated')}: #{rated.center(5)}"+N @main_string << "| #{palegreen('Genre')}: #{genre}"+N @main_string << "| #{indianred('Director')}: #{director}"+N @main_string << "| #{springgreen('Actors')}: #{actors}"+N # Add the Plot subsection next. # =================================================================== # @main_string << "| #{seagreen('Plot')}: #{plot}"+N # =================================================================== # @main_string << cliner+N display_main_string end end end
set_name_of_the_movie(i = '')
click to toggle source
#¶ ↑
set_name_of_the_movie
¶ ↑
#¶ ↑
# File lib/multimedia_paradise/video/movie_searcher.rb, line 95 def set_name_of_the_movie(i = '') i = i.join(' ').strip if i.is_a? Array i = i.to_s.dup.chomp.strip # ======================================================================= # # We may also do some sanitizing. First, get rid of the file extension # if the input includes a '.' token. # ======================================================================= # if i.include? '.' i.sub!(/#{File.extname(i)}/,'') end if i.include?('_') and (i =~ /^\d+/) use_this_regex = /\d{1,3}_(.+)/ # See: http://rubular.com/r/9fsrGiTQi1 i =~ use_this_regex i = $1.to_s.dup if $1 end @name_of_the_movie = i end