Class: ImdbLists
Instance Attribute Summary collapse
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
-
.fetch(url) ⇒ Object
Like this; www.imdb.com/list/qJi7_i3l25Y/ Raises an ArgumentError if the given url is invalid.
Instance Method Summary collapse
-
#csv ⇒ Object
String A url to the CVS file.
-
#initialize(url) ⇒ ImdbLists
constructor
Like this; www.imdb.com/list/qJi7_i3l25Y/.
-
#is_url_valid? ⇒ Boolean
Is @url a valid url?.
- #movies ⇒ Object
-
#name ⇒ Object
String Name for the given list.
Constructor Details
#initialize(url) ⇒ ImdbLists
Like this; www.imdb.com/list/qJi7_i3l25Y/
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/imdb_lists.rb', line 16 def initialize(url) @url = url @movie = Struct.new( :id, :created_at, :title, :directors, :you_rated, :rating, :runtime, :year, :genres, :votes, :released_at, :details, :order ) end |
Instance Attribute Details
#url ⇒ Object (readonly)
Returns the value of attribute url.
10 11 12 |
# File 'lib/imdb_lists.rb', line 10 def url @url end |
Class Method Details
.fetch(url) ⇒ Object
Like this; www.imdb.com/list/qJi7_i3l25Y/ Raises an ArgumentError if the given url is invalid.
41 42 43 44 45 46 47 48 |
# File 'lib/imdb_lists.rb', line 41 def self.fetch(url) this = ImdbLists.new(url) unless this.is_url_valid? raise ArgumentError.new("Invalid url") end return this end |
Instance Method Details
#csv ⇒ Object
Returns String A url to the CVS file.
53 54 55 56 57 |
# File 'lib/imdb_lists.rb', line 53 def csv if csv = content.at_css(".export a").try(:attr, "href") @_csv ||= "http://www.imdb.com%s" % csv end end |
#is_url_valid? ⇒ Boolean
Is @url a valid url?
87 88 89 |
# File 'lib/imdb_lists.rb', line 87 def is_url_valid? !! @url.to_s.match(url_validator) end |
#movies ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/imdb_lists.rb', line 69 def movies return @_movies if @_movies return [] unless csv vote_list = csv_content.first.count != 15 @_movies ||= csv_content[1..-1].map do |movie| if vote_list create_movie_from_vote_list(movie) else create_movie_from_regular_list(movie) end end end |
#name ⇒ Object
Returns String Name for the given list.
62 63 64 |
# File 'lib/imdb_lists.rb', line 62 def name @_user ||= content.at_css("h1.header").try(:content) end |