movieDB 0.2.2 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZjM4MWY0ZjliNThkY2U4YjcyZWNhMWY1NWIxZTY1NTJhYjkwZDllMw==
5
+ data.tar.gz: !binary |-
6
+ ZjVjMDg2M2ZkZGFlNjdmZGU5N2IxY2NkNGM0Yzk2YTc0MzU0ZDJlZg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ NzVhZTIwOGE1MTM4MDZiYmIxYTM1M2JkNzI0YjgwNTRlOGViMTI2NzNmZGQw
10
+ ZGMyZWRiYTU1MjQ3Zjg1N2NiNzA5ZDU5NzhkYjA0MWU5ZDVjMjRhZjIyNTRh
11
+ MmE5ZGNmMDFlMWQ3MjA4MWEwYzlhY2MyNjg0ZTRjMTE4MzVhNzg=
12
+ data.tar.gz: !binary |-
13
+ ZjlhYjYxMzNiNDIwODU0NGE2NTllNWMzYzFiYTZkNzA0MjYxMzJkZDRmYjBi
14
+ NTAxMjFmN2ZmYmZlMmFlMDEzNTllZTFjZDM2Njk5YjkwYTM2ODQ1ZmI0MDE1
15
+ ZGQ1NjUwMDI5NjYwZmJmMGZjZDQyOWRlYWVlNmNmMDdkOTFhNTM=
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ reports
data/.travis.yml ADDED
@@ -0,0 +1,30 @@
1
+ before_script:
2
+ #- sh -e /etc/init.d/xvfb start
3
+ #- export DISPLAY=99:0
4
+ bundler_args: --without development production --quiet
5
+ env:
6
+ #- GEM DB=sqlite
7
+ #- GEM DB=mysql
8
+ #- GEM DB=postgres
9
+ before_install:
10
+ - cd $GEM; export BUNDLE_GEMFILE="`pwd`/Gemfile"
11
+ script: bundle exec rspec spec
12
+
13
+ matrix:
14
+ allow_failures:
15
+ - rvm: 1.9.7
16
+ #- rvm: jruby
17
+ #- rvm: rbx
18
+ #- rvm: ree
19
+
20
+ notifications:
21
+ email: kotn_ep1@hotmail.com
22
+ webhooks:
23
+ on_success: always
24
+ on_failure: always
25
+
26
+ rvm:
27
+ # 1.9.3
28
+ - 1.9.7
29
+ #- 2.0.0
30
+ #- 2.1.0
data/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  MovieDB - Movie Data Analysis Tool
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/movieDB.png)](http://badge.fury.io/rb/movieDB)
4
-
3
+ [![Gem Version](https://badge.fury.io/rb/movieDB.png)](http://badge.fury.io/rb/movieDB) [![Code Climate](https://codeclimate.com/github/keeperofthenecklace/movieDB.png)](https://codeclimate.com/github/keeperofthenecklace/movieDB) [![Build Status](https://secure.travis-ci.org/keeperofthenecklace/movieDB.png?branch=master)](http://travis-ci.org/keeperofthenecklace/movieDB)
4
+ [![Join the chat at https://gitter.im/keeperofthenecklace/movieDB](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/keeperofthenecklace/movieDB?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
5
5
  ## Description
6
6
 
7
7
  Although the name suggests a datastore gem, MovieDB is actually a ruby wrapper that inspects, cleans, transform and model imdb data and provides useful data analysis information, suggesting conclusion. The objective and usage is to provide a tool that can aide movie/film producers make statistical decisions based off archival imdb data.
@@ -21,11 +21,13 @@ Please follow the URL links for reading info.
21
21
  * https://github.com/ahmetabdi/themoviedb
22
22
 
23
23
  ## Requirements
24
-
24
+
25
25
  ruby 1.9.x
26
-
26
+
27
27
  themoviedb api key
28
28
 
29
+ code formattted using TomDoc code documentation specification
30
+
29
31
  ## Installation
30
32
 
31
33
  Add this line to your application's Gemfile:
@@ -45,16 +47,18 @@ Or install it yourself as:
45
47
  $ irb
46
48
 
47
49
  > require 'movieDB'
48
-
50
+
49
51
  > require 'MovieDB/data_export'
50
-
52
+
51
53
  > require 'themoviedb'
52
54
 
53
- ## Usage - Collect Movie Data From IMDb (3 Steps)
55
+ ## Usage - Fetch Raw Movie Data From IMDb (3 Steps)
56
+
57
+ > MovieDB::Movie.new /* PRINTS OUT THE DEFAULT INITIALIZED VALUES */
54
58
 
55
59
  > MovieDB::Movie.clear_data_store /* ONLY IF YOUR WANT TO EMPTY YOUR DATASTORE (ARRAY) */
56
-
57
- > MovieDB::Movie.send(:get_multiple_imdb_movie_data, "2024544", "1800241", "0791314")
60
+
61
+ > MovieDB::Movie.send(:get_multiple_imdb_movie_data, "0369610", "3079380", "2395427")
58
62
 
59
63
  /* YOU CAN ADD AS MANY IMDB UNIQUE NUMBERS. DO NOT EXCEED MAXIMUM REQUEST RATE.*/
60
64
 
@@ -64,9 +68,11 @@ Or install it yourself as:
64
68
 
65
69
  The exported movie data is stored in your reports directory.
66
70
 
67
- $ open /reports/imdb_raw_data_20131216.xls
71
+ The file name is 'imdb_raw_data_' + today's date.
68
72
 
69
- ## Usage - Analyse Data and Generate Statistic Results (4 Steps)
73
+ $ open /reports/imdb_raw_data_20150608.xls
74
+
75
+ ## Usage - Analyze Raw Data and Generate Statistical Results (4 Steps)
70
76
 
71
77
  $ irb
72
78
 
@@ -76,7 +82,7 @@ The exported movie data is stored in your reports directory.
76
82
 
77
83
  > MovieDB::DataProcess.send(:basic_statistic, 'imdb_raw_data_20131216.xls')
78
84
 
79
- ### Exported - Analyzed Data
85
+ ### Exported - Analyzed Data
80
86
 
81
87
  The exported analyzed data is stored in your reports directory.
82
88
 
@@ -88,80 +94,80 @@ The exported analyzed data is stored in your reports directory.
88
94
 
89
95
  `:GaussNewtonAlgorithm`
90
96
 
91
- > Iteratively_Reweighted_Least_Squares
92
- > Lack_Of_Fit_Sum_Of_Squares
93
- > Least_Squares_Support_Vector_Machine
94
- > Mean_Squared_Error
95
- > Moving_Least_Sqares
96
- > Non_Linear_Iterative_Partial_Least_Squares
97
- > Non_Linear_Least_Squares
98
- > Ordinary_Least_Squares
99
- > Partial_Least_Squares_Regression
100
- > Partition_Of_Sums_Of_Squares
101
- > Proofs_Involving_Ordinary_Least_Squares
102
- > Residual_Sum_Of_Squares
103
- > Total_Least_Squares
104
- > Total_Sum_Of_Squares
105
-
97
+ > Iteratively_Reweighted_Least_Squares
98
+ > Lack_Of_Fit_Sum_Of_Squares
99
+ > Least_Squares_Support_Vector_Machine
100
+ > Mean_Squared_Error
101
+ > Moving_Least_Sqares
102
+ > Non_Linear_Iterative_Partial_Least_Squares
103
+ > Non_Linear_Least_Squares
104
+ > Ordinary_Least_Squares
105
+ > Partial_Least_Squares_Regression
106
+ > Partition_Of_Sums_Of_Squares
107
+ > Proofs_Involving_Ordinary_Least_Squares
108
+ > Residual_Sum_Of_Squares
109
+ > Total_Least_Squares
110
+ > Total_Sum_Of_Squares
111
+
106
112
  `:EstimationOfDensity`
107
113
 
108
- > Cluster_Weighted_Modeling
109
- > Density_Estimation
110
- > Discretization_Of_Continuous_Features
111
- > Mean_Integrated_Squared_Error
112
- > Multivariate_Kernel_Density_Estimation
113
- > Variable_Kernel_Density_Estimation
114
-
114
+ > Cluster_Weighted_Modeling
115
+ > Density_Estimation
116
+ > Discretization_Of_Continuous_Features
117
+ > Mean_Integrated_Squared_Error
118
+ > Multivariate_Kernel_Density_Estimation
119
+ > Variable_Kernel_Density_Estimation
120
+
115
121
  `:ExploratoryDataAnalysis`
116
122
 
117
- > Data_Reduction
118
- > Table_Diagonalization
119
- > Configural_Frequency_Analysis
120
- > Median_Polish
121
- > Stem_And_Leaf_Display
122
-
123
+ > Data_Reduction
124
+ > Table_Diagonalization
125
+ > Configural_Frequency_Analysis
126
+ > Median_Polish
127
+ > Stem_And_Leaf_Display
128
+
123
129
  > Data_Mining
124
- > Applied_DataMining
125
- > Cluster_Analysis
126
- > Dimension_Reduction
127
- > Applied_DataMining
128
-
130
+ > Applied_DataMining
131
+ > Cluster_Analysis
132
+ > Dimension_Reduction
133
+ > Applied_DataMining
134
+
129
135
  > RegressionAnalysis
130
- > Choice_Modelling
131
-
132
- > Generalized_Linear_Model
133
- > Binomial_Regression
134
- > Generalized_Additive_Model
135
- > Linear_Probability_Model
136
- > Poisson_Regression
137
- > Zero_Inflated_Model
138
-
139
- > Nonparametric_Regression
140
- > Statistical_Outliers
141
- > Regression_And_Curve_Fitting_Software
142
- > Regression_Diagnostics
143
- > Regression_Variable_Selection
144
- > Regression_With_Time_Series_Structure
145
- > Robust_Regression
146
- > Choice_Modeling
147
-
136
+ > Choice_Modelling
137
+
138
+ > Generalized_Linear_Model
139
+ > Binomial_Regression
140
+ > Generalized_Additive_Model
141
+ > Linear_Probability_Model
142
+ > Poisson_Regression
143
+ > Zero_Inflated_Model
144
+
145
+ > Nonparametric_Regression
146
+ > Statistical_Outliers
147
+ > Regression_And_Curve_Fitting_Software
148
+ > Regression_Diagnostics
149
+ > Regression_Variable_Selection
150
+ > Regression_With_Time_Series_Structure
151
+ > Robust_Regression
152
+ > Choice_Modeling
153
+
148
154
  > Resampling
149
- > Bootstrapping_Population
150
-
155
+ > Bootstrapping_Population
156
+
151
157
  > Sensitivity_Analysis
152
- > Variance_Based_Sensitivity_Analysis
153
- > Elementary_Effects_Method
154
- > Experimental_Uncertainty_Analysis
155
- > Fourier_Amplitude_Sensitivity_Testing
156
- > Hyperparameter
157
-
158
+ > Variance_Based_Sensitivity_Analysis
159
+ > Elementary_Effects_Method
160
+ > Experimental_Uncertainty_Analysis
161
+ > Fourier_Amplitude_Sensitivity_Testing
162
+ > Hyperparameter
163
+
158
164
  > Time_Series_Analysis
159
- > Frequency_Deviation
165
+ > Frequency_Deviation
160
166
 
161
167
  ## Contact me
162
168
 
163
- If you'd like to collaborate, please feel free to fork source code on github.
169
+ If you'd like to collaborate, please feel free to fork source code on github.
164
170
 
165
171
  You can also contact me at albertmck@gmail.com
166
172
 
167
- ###### Copyright (c) 2013 Albert McKeever, released under MIT license
173
+ ###### Copyright (c) 2013 Albert McKeever, released under MIT license
data/lib/movieDB.rb CHANGED
@@ -1,293 +1,250 @@
1
1
  require "rubygems"
2
- require "time"
3
- require "open-uri"
4
- require "nokogiri"
5
- require "zimdb"
6
- require "themoviedb"
7
- require "imdb"
8
- require "spreadsheet"
2
+ require "time" # Time is an abstraction of dates and times.
3
+ require "open-uri" # is an easy-to-use wrapper for net/http, net/https and net/ftp.
4
+ require "nokogiri" # is an HTML, XML, SAX, and Reader parser.
5
+ require "zimdb" # Access movie information from IMDb via the API offered by http://www.imdbapi.com/
6
+ require "themoviedb" # Provides a simple, easy to use interface for the Movie Database API.
7
+ require "imdb" # Easily use Ruby or the command line to find information on IMDB.com.
8
+ require "spreadsheet" # A library designed to read and write Spreadsheet Documents.
9
9
  require "MovieDB/base"
10
10
  require "MovieDB/data_analysis"
11
11
  require "MovieDB/secret"
12
- ##
12
+
13
+ unless defined? MovieDB::Movie
14
+ module MovieDB #:nodoc:
13
15
  # Create a new movie record. The values are stored in the key-value data store.
14
16
  #
15
17
  # Default values are supplement during the instantiation of the class.
16
18
  # Those values are overriden when you provide one.
17
19
  #
18
- # Example
19
- # movie = Movie.new()
20
- # movie.title = "When Sally Met Harry"
21
-
22
- unless defined? MovieDB::Movie
23
- module MovieDB
24
- class Movie < MovieDB::Base
25
-
26
- include StatusChecker
27
- extend MovieDB::Secret::Lock
28
-
29
- # Use example
30
- # raise MovieError unless Movie.title_present?
31
-
32
- const_set("MovieError", Class.new(StandardError))
33
-
34
- attr_accessor :title,
35
- :cast_members,
36
- :cast_characters,
37
- :cast_member_ids,
38
- :cast_members_characters,
39
- :trailer_url,
40
- :director,
41
- :writer,
42
- :filming_locations,
43
- :company,
44
- :genres,
45
- :languages,
46
- :countries,
47
- :length,
48
- :plot,
49
- :poster,
50
- :rating,
51
- :votes,
52
- :mpaa_rating,
53
- :tagline,
54
- :year,
55
- :release_date,
56
- :worldwide_gross,
57
- :released,
58
- :unique_id,
59
- :academy_award_nomination,
60
- :academy_award_wins,
61
- :golden_globe_nominations,
62
- :golden_globe_wins,
63
- :bafta_nomination,
64
- :bafta_wins,
65
- :film_release
66
-
67
- DEFAULT_TITLE = "Method Missing 2: Rails Roars!"
68
- DEFAULT_CAST_MEMBERS = ["David Black", "Paola Perotta", "Obie Fernandez", "David Chelimsky"]
69
- DEFAULT_CAST_CHARACTERS = ["Developer", "Police Officer", "Hunter", "Hostage"]
70
- DEFAULT_CAST_MEMBERS_CHARACTERS = ["David Black => Developer", "Paola Perotta => Police Officer",
71
- "Obie Fernandez =>Hunter", "David Chelimsky =>Hostage"]
72
- DEFAULT_CAST_MEMBER_IDS = ["nm3901234", "nm4901244", "nm5901235", "nm3601266"]
73
- DEFAULT_TRAILER_URL = "http://imdb.com/video/screenplay/vi581042457/"
74
- DEFAULT_DIRECTOR = "Yukihiro 'Matz' Matsumoto"
75
- DEFAULT_WRITER = 'David Heinemeier Hansson'
76
- DEFAULT_FILMING_LOCATIONS = ["Manhattan, New York, USA"]
77
- DEFAULT_COMPANY = "Open Source Community Film Corporation"
78
- DEFAULT_GENRES = ["Bromantic", "Syfy"]
79
- DEFAULT_LANGUAGES = ["English", "German", "Italian"]
80
- DEFAULT_COUNTRIES = ["USA", "Germany", "Italy"]
81
- DEFAULT_LENGTH = 146
82
- DEFAULT_PLOT = ["David Black, a ruby developer, tries to write his flagship ruby book 'The Well-Grounded Rubyist vol. 186' only to find out that Ruby 9.0.2 and Rails 16.0.3 release dates have been postponed"]
83
- DEFAULT_POSTER = "http://ia.media-imdb.com/images/M/MV5BMTY@@.jpg"
84
- DEFAULT_RATING = 9.9
85
- DEFAULT_VOTES = 110636
86
- DEFAULT_MPAA_RATING = "Rated R for dynamic OOD language usage and private methods access (certificate 33087)"
87
- DEFAULT_TAGLINE = 'Only One MVC Will rule Them All.'
88
- DEFAULT_YEAR = 2013
89
- DEFAULT_RELEASE_DATE = "11 October 2013 (USA)"
90
- DEFAULT_WORLDWIDE_GROSS = "$124.6M" # Not provided by imdb api.
91
- DEFAULT_UNIQUE_ID = @unique_id
92
- DEFAULT_ACADEMY_AWARD_NOMINATION = 4
93
- DEFAULT_ACADEMY_AWARD_WINS = 3
94
- DEFAULT_GOLDEN_GLOBE_NOMINATIONS = 4
95
- DEFAULT_GOLDEN_GLOBE_WINS = 2
96
- DEFAULT_BAFTA_NOMINATION = 3
97
- DEFAULT_BAFTA_WINS = 1
98
- DEFAULT_FILM_RELEASE = ['theatrical', 'video', 'television', 'internet', 'print']
99
-
100
-
101
- def initialize(attributes = {})
102
- $IMDB_ATTRIBUTES_HEADERS = movie_attr = %w(title cast_members cast_characters cast_member_ids cast_members_characters
103
- trailer_url director writer filming_locations company genres languages countries
104
- length plot poster rating votes mpaa_rating tagline year release_date worldwide_gross unique_id
105
- academy_award_nomination academy_award_wins golden_globe_nominations golden_globe_wins
106
- bafta_nomination bafta_wins film_release )
107
- movie_attr.each do |attr|
108
- self.send "#{attr}=", (attributes.has_key?(attr.to_sym) ? attributes[attr.to_sym] : self.class.const_get("DEFAULT_#{attr.upcase}"))
109
- end
110
- end
111
-
112
- ##
113
- # Iterating through the block for title duplication.
114
- # Return a true if the array is not nil.
115
- # Absence of title duplications should yield an empty array.
20
+ # You can use it like this:
21
+ #
22
+ # movie = Movie.new()
23
+ # movie.title = "When Sally Met Harry"
24
+ #
25
+ # You can raise a MovieError like this:
26
+ #
27
+ # raise MovieError unless Movie.title_present?
28
+ class Movie < MovieDB::Base
29
+ include StatusChecker
30
+
31
+ extend MovieDB::Secret::Lock
32
+
33
+ const_set("MovieError", Class.new(StandardError))
34
+
35
+ attr_accessor :title,
36
+ :cast_members,
37
+ :cast_characters,
38
+ :cast_member_ids,
39
+ :cast_members_characters,
40
+ :trailer_url,
41
+ :director,
42
+ :writer,
43
+ :filming_locations,
44
+ :company,
45
+ :genres,
46
+ :languages,
47
+ :countries,
48
+ :length,
49
+ :plot,
50
+ :poster,
51
+ :rating,
52
+ :votes,
53
+ :mpaa_rating,
54
+ :tagline,
55
+ :year,
56
+ :release_date,
57
+ :worldwide_gross,
58
+ :released,
59
+ :unique_id,
60
+ :academy_award_nomination,
61
+ :academy_award_wins,
62
+ :golden_globe_nominations,
63
+ :golden_globe_wins,
64
+ :bafta_nomination,
65
+ :bafta_wins,
66
+ :film_release
67
+
68
+ DEFAULT_TITLE = "Method Missing 2: Rails Roars!"
69
+ DEFAULT_CAST_MEMBERS = ["David Black", "Paola Perotta", "Obie Fernandez", "David Chelimsky"]
70
+ DEFAULT_CAST_CHARACTERS = ["Developer", "Police Officer", "Hunter", "Hostage"]
71
+ DEFAULT_CAST_MEMBERS_CHARACTERS = ["David Black => Developer", "Paola Perotta => Police Officer",
72
+ "Obie Fernandez =>Hunter", "David Chelimsky =>Hostage"]
73
+ DEFAULT_CAST_MEMBER_IDS = ["nm3901234", "nm4901244", "nm5901235", "nm3601266"]
74
+ DEFAULT_TRAILER_URL = "http://imdb.com/video/screenplay/vi581042457/"
75
+ DEFAULT_DIRECTOR = "Yukihiro 'Matz' Matsumoto"
76
+ DEFAULT_WRITER = 'David Heinemeier Hansson'
77
+ DEFAULT_FILMING_LOCATIONS = ["Manhattan, New York, USA"]
78
+ DEFAULT_COMPANY = "Open Source Community Film Corporation"
79
+ DEFAULT_GENRES = ["Bromantic", "Syfy"]
80
+ DEFAULT_LANGUAGES = ["English", "German", "Italian"]
81
+ DEFAULT_COUNTRIES = ["USA", "Germany", "Italy"]
82
+ DEFAULT_LENGTH = 146
83
+ DEFAULT_PLOT = ["David Black, a ruby developer, tries to write his flagship ruby book 'The Well-Grounded Rubyist vol. 186' only to find out that Ruby 9.0.2 and Rails 16.0.3 release dates have been postponed"]
84
+ DEFAULT_POSTER = "http://ia.media-imdb.com/images/M/MV5BMTY@@.jpg"
85
+ DEFAULT_RATING = 9.9
86
+ DEFAULT_VOTES = 110636
87
+ DEFAULT_MPAA_RATING = "Rated R for dynamic OOD language usage and private methods access (certificate 33087)"
88
+ DEFAULT_TAGLINE = 'Only One MVC Will Rule Them All.'
89
+ DEFAULT_YEAR = 2013
90
+ DEFAULT_RELEASE_DATE = "11 October 2013 (USA)"
91
+ DEFAULT_WORLDWIDE_GROSS = "$124.6M" # Not provided by imdb api.
92
+ DEFAULT_UNIQUE_ID = @unique_id
93
+ DEFAULT_ACADEMY_AWARD_NOMINATION = 4
94
+ DEFAULT_ACADEMY_AWARD_WINS = 3
95
+ DEFAULT_GOLDEN_GLOBE_NOMINATIONS = 4
96
+ DEFAULT_GOLDEN_GLOBE_WINS = 2
97
+ DEFAULT_BAFTA_NOMINATION = 3
98
+ DEFAULT_BAFTA_WINS = 1
99
+ DEFAULT_FILM_RELEASE = ['theatrical', 'video', 'television', 'internet', 'print']
100
+ def initialize(attributes = {})
101
+ $IMDB_ATTRIBUTES_HEADERS = movie_attr = %w(title cast_members cast_characters cast_member_ids cast_members_characters
102
+ trailer_url director writer filming_locations company genres languages countries
103
+ length plot poster rating votes mpaa_rating tagline year release_date worldwide_gross unique_id
104
+ academy_award_nomination academy_award_wins golden_globe_nominations golden_globe_wins
105
+ bafta_nomination bafta_wins film_release)
106
+
107
+ movie_attr.each do |attr|
108
+ self.send("#{attr}=", (attributes.has_key?(attr.to_sym) ? attributes[attr.to_sym] : self.class.const_get("DEFAULT_#{attr.upcase}")))
109
+ end
116
110
 
117
- def self.title_present?
118
- titles = Movie.instance_eval{filter_movie_attr("title")}
119
- @title_exist = titles.detect{|duplicates|titles.count(duplicates) > 1}
120
- !@title_exist.nil?
121
- end
111
+ end
112
+
113
+ # Iterating through the block for title duplication.
114
+ # Return true if the array is not nil.
115
+ # Absence of title duplications should yield an empty array.
116
+ def self.title_present?
117
+ titles = Movie.instance_eval { filter_movie_attr("title") }
118
+ @title_exist = titles.detect { |duplicates| titles.count(duplicates) > 1 }
119
+ !@title_exist.nil?
120
+ end
121
+
122
+ def unique_id
123
+ @unique_id ||= "#{Date.today}#{Array.new(9){rand(9)}.join}".gsub('-','')
124
+ end
125
+
126
+ class << self
127
+ # Get a single data from imdb database.
128
+ #
129
+ # TODO: This method should be deprecated in the next version release.
130
+ def get_imdb_movie_data(value)
131
+ @movie_data = Imdb::Movie.new(value)
132
+ return @movie_data
133
+ end
122
134
 
123
- def unique_id
124
- @unique_id ||= "#{Date.today}#{Array.new(9){rand(9)}.join}".gsub('-','')
135
+ def global_movie_data_store
136
+ return $GLOBAL_MOVIE_DS
137
+ end
138
+ # You can add multiple Imdb ids like this:
139
+ #
140
+ # MovieDB::Movie.send(:get_multiple_imdb_movie_data, "2024544", "1800241")
141
+ #
142
+ # Example: You can also collect the title attribute:
143
+ #
144
+ # MovieDB::Movie.instance_eval{filter_movie_attr("title")}
145
+ def get_multiple_imdb_movie_data(*args)
146
+ if args.size == 1
147
+ puts "*" * 41
148
+ puts "* A minimum of 2 Imdb id's are required *"
149
+ puts "* To perform statistical data analysis *"
150
+ puts "* You only have ONE Imdb id entered *"
151
+ puts "*" * 41
125
152
  end
126
153
 
127
-
128
- class << self
129
-
130
- ##
131
- # Get the single data from imdb
132
- #
133
- # TODO: This method should be deprecated in the next version release.
134
-
135
- def get_imdb_movie_data(value)
136
- puts zimdb_value = "tt" << value.to_s
137
- @movie_data = Imdb::Movie.new(value.to_s)
138
- @zimdb_data = Zimdb::Movie.new( :id => zimdb_value)
139
-
140
- return @movie_data
141
- return @zimdb_data
154
+ args.each do |value|
155
+ get_imdb_movie_data(value)
156
+ @movie_DS ||=[]
157
+ movie_info = Movie.new
158
+
159
+ # Query themoviedb.org for film revenue.
160
+ # returns 0 if revenue record doesn't exist.
161
+ tmdb_arr = []
162
+ tmdb_key = MovieDB::Movie.key
163
+ Tmdb::Api.key(tmdb_key)
164
+ tmdb = Tmdb::Movie.find(@movie_data.title)
165
+
166
+ if tmdb.empty?
167
+ tmdb_data = Tmdb::Movie.new
168
+ tmdb_data.revenue = 0
169
+ else
170
+ tmdb.select { |t| tmdb_arr << t.id }
171
+ tmdb_id = tmdb_arr[0]
172
+ tmdb_data = Tmdb::Movie.detail(tmdb_id)
142
173
  end
143
174
 
144
- def global_movie_data_store
145
- return $GLOBAL_MOVIE_DS
146
- end
147
-
148
- ##
149
- # You can add multiple Imdb ids
150
- #
151
- # USAGE # MovieDB::Movie.send(:get_multiple_imdb_movie_data, "2024544", "1800241")
152
- # #
153
- # # Example: You can collect the arrays of the title attributes
154
- # #
155
- # # MovieDB::Movie.instance_eval{filter_movie_attr("title")}
156
-
157
- def get_multiple_imdb_movie_data(*args)
158
-
159
- ##
160
- # Notify user to input in 2 or more imdb id's
161
-
162
- if args.size == 1
163
- puts "*"*41
164
- puts "* A minimum of 2 Imdb id's are required *"
165
- puts "* To perform statistical data analysis *"
166
- puts "* You only have ONE Imdb id entered *"
167
- puts "*"*41
168
- end
169
-
170
- args.each do |value|
171
- get_imdb_movie_data(value)
172
- @movie_DS ||=[]
173
- movie_info = Movie.new
174
-
175
- ##
176
- # query themoviedb.org for film revenue
177
- # Will return a 0 revenue if record doesn't exist at
178
- # themoviedb.org
179
-
180
- tmdb_arr = []
181
- tmdb_key = MovieDB::Movie.key
182
- Tmdb::Api.key(tmdb_key)
183
- tmdb = Tmdb::Movie.find(@movie_data.title)
184
-
185
- if tmdb.empty?
186
- tmdb_data = Tmdb::Movie.new
187
- tmdb_data.revenue = 0
188
- else
189
- tmdb.select { |t| tmdb_arr << t.id }
190
- tmdb_id = tmdb_arr[0]
191
- tmdb_data = Tmdb::Movie.detail(tmdb_id)
192
- end
193
- begin
194
- movie_info.title = Array.new << @movie_data.title
195
- movie_info.cast_members = @movie_data.cast_members.flatten
196
- movie_info.cast_characters = @movie_data.cast_characters
197
- movie_info.cast_member_ids = @movie_data.cast_member_ids
198
- movie_info.cast_members_characters = @movie_data.cast_members_characters
199
- movie_info.trailer_url = @movie_data.trailer_url.nil? ? 'No Trailer' : @movie_data.trailer_url
200
- movie_info.director = @movie_data.director.flatten
201
- movie_info.writer = Array.new << @zimdb_data.writer
202
- movie_info.filming_locations = @movie_data.filming_locations.flatten.join(', ')
203
- movie_info.company = Array.new << @movie_data.company
204
- movie_info.genres = @movie_data.genres.flatten.join(' ').sub(' ' , ', ')
205
- movie_info.languages = Array.new << @movie_data.languages.flatten.join(' ').sub(' ' , ', ')
206
- movie_info.countries = Array.new << @movie_data.countries.flatten.join(' ').sub(' ' , ', ')
207
- movie_info.length = Array.new << @movie_data.length
208
- movie_info.plot = Array.new << @movie_data.plot
209
- movie_info.poster = Array.new << @movie_data.poster
210
- movie_info.rating = Array.new << @movie_data.rating
211
- movie_info.votes = Array.new << @movie_data.votes
212
- movie_info.mpaa_rating = Array.new << @movie_data.mpaa_rating == [nil] ? ["Not Rated"] : [@movie_data.mpaa_rating]
213
- movie_info.tagline = Array.new << @movie_data.tagline
214
- movie_info.year = Array.new << @movie_data.year
215
- movie_info.release_date = Array.new << @movie_data.release_date
216
- movie_info.worldwide_gross = Array.new << tmdb_data.revenue
217
- movie_info.unique_id = @unique_id
218
-
219
- ##
220
- # TODO: Write API to request data from AMPAS.
221
-
222
- #movie_info.academy_award_nomination = academy_award_nomination
223
- #movie_info.academy_award_wins = academy_award_wins
224
- #movie_info.golden_globe_nominations = golden_globe_nominations
225
- #movie_info.golden_globe_wins = golden_globe_wins
226
- #movie_info.bafta_nomination = bafta_nomination
227
- #movie_info.bafta_wins = bafta_wins
228
- $GLOBAL_MOVIE_DS = @movie_DS << movie_info
229
- rescue
230
- raise ArgumentError, 'invalid imbd id'
231
- end
232
- end
233
-
234
- return @movie_DS
235
-
236
- ##
237
- #TODO: Include this for later data analysis computation
238
-
239
- #if Movie.title_present?
240
- #raise ArgumentError, "The title #{@title_exist} has already been taking"
241
- #else
242
- #return @movie_DS
243
- #end
244
-
245
- end
246
-
247
- # Empty the data store
248
- # Reset to nil
249
-
250
- def clear_data_store
251
- @movie_DS = []
252
- return @movie_DS
175
+ begin
176
+ movie_info.title = Array.new << @movie_data.title
177
+ movie_info.cast_members = @movie_data.cast_members.flatten
178
+ movie_info.cast_characters = @movie_data.cast_characters
179
+ movie_info.cast_member_ids = @movie_data.cast_member_ids
180
+ movie_info.cast_members_characters = @movie_data.cast_members_characters
181
+ movie_info.trailer_url = @movie_data.trailer_url.nil? ? 'No Trailer' : @movie_data.trailer_url
182
+ movie_info.director = @movie_data.director.flatten
183
+ movie_info.writer = @movie_data.writers.flatten
184
+ movie_info.filming_locations = @movie_data.filming_locations.flatten.join(', ')
185
+ movie_info.company = Array.new << @movie_data.company
186
+ movie_info.genres = @movie_data.genres.flatten.join(' ').sub(' ' , ', ')
187
+ movie_info.languages = Array.new << @movie_data.languages.flatten.join(' ').sub(' ' , ', ')
188
+ movie_info.countries = Array.new << @movie_data.countries.flatten.join(' ').sub(' ' , ', ')
189
+ movie_info.length = Array.new << @movie_data.length
190
+ movie_info.plot = Array.new << @movie_data.plot
191
+ movie_info.poster = Array.new << @movie_data.poster
192
+ movie_info.rating = Array.new << @movie_data.rating
193
+ movie_info.votes = Array.new << @movie_data.votes
194
+ movie_info.mpaa_rating = Array.new << @movie_data.mpaa_rating == [nil] ? ["Not Rated"] : [@movie_data.mpaa_rating]
195
+ movie_info.tagline = Array.new << @movie_data.tagline
196
+ movie_info.year = Array.new << @movie_data.year
197
+ movie_info.release_date = Array.new << @movie_data.release_date
198
+ movie_info.worldwide_gross = Array.new << tmdb_data["revenue"]
199
+ movie_info.unique_id = @unique_id
200
+
201
+ # TODO: Write API to request additional data from AMPAS.
202
+ #
203
+ # Example: We can fetch the data like this:
204
+ #
205
+ # movie_info.academy_award_nomination = academy_award_nomination
206
+ # movie_info.academy_award_wins = academy_award_wins
207
+ # movie_info.golden_globe_nominations = golden_globe_nominations
208
+ # movie_info.golden_globe_wins = golden_globe_wins
209
+ # movie_info.bafta_nomination = bafta_nomination
210
+ # movie_info.bafta_wins = bafta_wins
211
+ $GLOBAL_MOVIE_DS = @movie_DS << movie_info
212
+ rescue
213
+ raise ArgumentError, 'invalid imbd id'
253
214
  end
215
+ end
254
216
 
255
- ##
256
- # Filter the data store for the movie attributes. Return an array of the attributes.
257
- #
258
- # Example.
259
- # Movie.filter_movie_attr('cast_members') #=> ["Chris_Hemsworth", "Natalie_Portman"]
217
+ return @movie_DS
218
+ end
260
219
 
261
- def filter_movie_attr(attr)
262
- attr_raw = attr
263
- attr_sym = attr.to_sym
220
+ def clear_data_store
221
+ @movie_DS = []
264
222
 
265
- raise ArgumentError, "#{attr_sym} is not a valid attribute." if !attr_sym == :director && :cast_members
266
- filtered = @movie_DS.select{|ds| ds.attr_title?}.map(&attr_sym)#.flatten
267
- attr_raw == ('languages' && 'title') ? filtered : filtered#.uniq
268
- end
269
- end
270
- private_class_method :get_multiple_imdb_movie_data, :filter_movie_attr, :get_imdb_movie_data
223
+ return @movie_DS
224
+ end
271
225
 
272
- def attr_title
273
- !@title.nil?
274
- end
275
- alias :attr_title? :attr_title
226
+ # Filter the data store for the movie attributes. Return an array of the attributes.
227
+ #
228
+ # Example
229
+ #
230
+ # Movie.filter_movie_attr('cast_members') #=> ["Chris_Hemsworth", "Natalie_Portman"]
231
+ def filter_movie_attr(attr)
232
+ attr_raw = attr
233
+ attr_sym = attr.to_sym
234
+
235
+ raise ArgumentError, ("#{attr_sym} is not a valid attribute." if !attr_sym == :director && :cast_members)
236
+ filtered = @movie_DS.select{ |ds| ds.attr_title? }.map(&attr_sym)#.flatten
237
+ attr_raw == ('languages' && 'title') ? filtered : filtered#.uniq
238
+ end
239
+ end
276
240
 
277
- ##
278
- # Use the double splat to capture auxillary arguments.
279
- # Will use this feature in Ruby 2.0 upgrade.
280
- # Currently, the software requirement is Ruby 1.9.x
281
- #
282
- # USAGE: capture(synopsis: "Last Vegas - Four geriatric friends vow to set Las Vegas Ablaze.")
241
+ private_class_method :get_multiple_imdb_movie_data, :filter_movie_attr, :get_imdb_movie_data
283
242
 
284
- #def capture(**opts)
285
- #@synopsis = opts
286
- #end
243
+ def attr_title
244
+ !@title.nil?
245
+ end
246
+ alias :attr_title? :attr_title
287
247
 
288
- #def wrap(synopsis, before: "(", after: ")")
289
- #"#{before}#{synopsis}#{after}"
290
- #end
291
- end
292
248
  end
249
+ end
293
250
  end