imdb 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.2.0 2009-06-04
2
+
3
+ * Added console tool 'imdb' for searching and getting movie info.
4
+ * Fixed issue #2
5
+
1
6
  == 0.1.0 2009-06-03
2
7
 
3
8
  * Added Imdb::Search that allows search IMDB for a specific movie.
data/Manifest.txt CHANGED
@@ -2,13 +2,16 @@ History.txt
2
2
  Manifest.txt
3
3
  README.rdoc
4
4
  Rakefile
5
+ bin/imdb
5
6
  lib/imdb.rb
7
+ lib/imdb/cli.rb
6
8
  lib/imdb/movie.rb
7
9
  lib/imdb/search.rb
8
10
  lib/imdb/string_extensions.rb
9
11
  script/console
10
12
  script/destroy
11
13
  script/generate
14
+ spec/imdb_cli_spec.rb
12
15
  spec/imdb_movie_spec.rb
13
16
  spec/imdb_search_spec.rb
14
17
  spec/spec.opts
data/bin/imdb ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Created on 2009-6-4.
4
+ # Copyright (c) 2009. All rights reserved.
5
+
6
+ require File.expand_path(File.dirname(__FILE__) + "/../lib/imdb")
7
+
8
+ require "imdb/cli"
9
+
10
+ Imdb::CLI.execute(STDOUT, ARGV)
data/lib/imdb.rb CHANGED
@@ -10,5 +10,5 @@ require 'imdb/search'
10
10
  require 'imdb/string_extensions'
11
11
 
12
12
  module Imdb
13
- VERSION = '0.1.0'
13
+ VERSION = '0.2.0'
14
14
  end
data/lib/imdb/cli.rb ADDED
@@ -0,0 +1,100 @@
1
+ require 'optparse'
2
+
3
+ module Imdb
4
+ class CLI
5
+
6
+ # Run the imdb command
7
+ #
8
+ # Searching
9
+ #
10
+ # imdb Star Trek
11
+ #
12
+ # Get a movie, supply a 7 digit IMDB id
13
+ #
14
+ # imdb 0095016
15
+ #
16
+ def self.execute(stdout, arguments=[])
17
+
18
+ @stdout = stdout
19
+
20
+ options = {
21
+ }
22
+ mandatory_options = %w( )
23
+
24
+ parser = OptionParser.new do |opts|
25
+ opts.banner = <<-BANNER.gsub(/^ /,'')
26
+ IMDB #{Imdb::VERSION}
27
+
28
+ Usage: #{File.basename($0)} Search Query
29
+ #{File.basename($0)} 0095016
30
+
31
+ BANNER
32
+ opts.separator ""
33
+ opts.on("-v", "--version",
34
+ "Show the current version.") { stdout.puts "IMDB #{Imdb::VERSION}"; exit }
35
+ opts.on("-h", "--help",
36
+ "Show this help message.") { stdout.puts opts; exit }
37
+ opts.parse!(arguments)
38
+
39
+ if mandatory_options && mandatory_options.find { |option| options[option.to_sym].nil? }
40
+ stdout.puts opts; exit
41
+ end
42
+ end
43
+
44
+ query = arguments.join(" ").strip
45
+ exit if query.blank?
46
+
47
+ movie, search = nil, nil
48
+
49
+ # If ID, fetch movie
50
+ if query.match(/\d\d\d\d\d\d\d/)
51
+ fetch_movie(query)
52
+ else
53
+ search_movie(query)
54
+ end
55
+ end
56
+
57
+ def self.fetch_movie(imdb_id)
58
+ @stdout.puts ">> Fetching movie #{imdb_id}"
59
+
60
+ movie = Imdb::Movie.new(imdb_id)
61
+
62
+ display_movie_details(movie)
63
+ end
64
+
65
+ def self.search_movie(query)
66
+ @stdout.puts ">> Searching for \"#{query}\""
67
+
68
+ search = Imdb::Search.new(query)
69
+
70
+ if search.movies.size == 1
71
+ display_movie_details(search.movies.first)
72
+ else
73
+ display_search_results(search.movies)
74
+ end
75
+ end
76
+
77
+ def self.display_movie_details(movie)
78
+ @stdout.puts
79
+ @stdout.puts "#{movie.title} (#{movie.year})"
80
+ @stdout.puts "=" * 72
81
+ @stdout.puts "Rating: #{movie.rating}"
82
+ @stdout.puts "Duration: #{movie.length} minutes"
83
+ @stdout.puts "Directed by: #{movie.director}"
84
+ @stdout.puts "Cast by: #{movie.cast_members[0..4].join(", ")}"
85
+ @stdout.puts "Genres: #{movie.genres.join(", ")}"
86
+ @stdout.puts "#{movie.plot}"
87
+ @stdout.puts "=" * 72
88
+ @stdout.puts
89
+ end
90
+
91
+ def self.display_search_results(movies = [])
92
+ movies = movies[0..9] # limit to ten top hits
93
+
94
+ movies.each do |movie|
95
+ @stdout.puts " > #{movie.id} | #{movie.title}"
96
+ end
97
+ end
98
+
99
+ end
100
+ end
data/lib/imdb/movie.rb CHANGED
@@ -17,7 +17,7 @@ module Imdb
17
17
  def initialize(imdb_id, title = nil)
18
18
  @id = imdb_id
19
19
  @url = "http://www.imdb.com/title/tt#{imdb_id}/"
20
- @title = title
20
+ @title = title.gsub(/"/, "")
21
21
  end
22
22
 
23
23
  # Returns an array with cast members
@@ -0,0 +1,34 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'imdb/cli'
3
+
4
+ describe Imdb::CLI, "execute" do
5
+
6
+ describe "yield search results" do
7
+ before(:each) do
8
+ @stdout_io = StringIO.new
9
+ Imdb::CLI.execute(@stdout_io, ["Star Trek"])
10
+ @stdout_io.rewind
11
+ @stdout = @stdout_io.read
12
+ end
13
+
14
+ it "report data" do
15
+ @stdout.should =~ /0060028/
16
+ @stdout.should =~ /Star Trek/
17
+ @stdout.should =~ /1966/
18
+ end
19
+ end
20
+
21
+ describe "yield one movie" do
22
+ before(:each) do
23
+ @stdout_io = StringIO.new
24
+ Imdb::CLI.execute(@stdout_io, ["0117731"])
25
+ @stdout_io.rewind
26
+ @stdout = @stdout_io.read
27
+ end
28
+
29
+ it "report data" do
30
+ @stdout.should =~ /Star Trek\: First Contact \(1996\)/
31
+ @stdout.should =~ /Jonathan Frakes/
32
+ end
33
+ end
34
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: imdb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ariejan de Vroom
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-03 00:00:00 +02:00
12
+ date: 2009-06-04 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -55,8 +55,8 @@ dependencies:
55
55
  description: This packages allows you to easy access publicly available data from IMDB.
56
56
  email:
57
57
  - ariejan@ariejan.net
58
- executables: []
59
-
58
+ executables:
59
+ - imdb
60
60
  extensions: []
61
61
 
62
62
  extra_rdoc_files:
@@ -68,13 +68,16 @@ files:
68
68
  - Manifest.txt
69
69
  - README.rdoc
70
70
  - Rakefile
71
+ - bin/imdb
71
72
  - lib/imdb.rb
73
+ - lib/imdb/cli.rb
72
74
  - lib/imdb/movie.rb
73
75
  - lib/imdb/search.rb
74
76
  - lib/imdb/string_extensions.rb
75
77
  - script/console
76
78
  - script/destroy
77
79
  - script/generate
80
+ - spec/imdb_cli_spec.rb
78
81
  - spec/imdb_movie_spec.rb
79
82
  - spec/imdb_search_spec.rb
80
83
  - spec/spec.opts