Class: ImdbLists

Inherits:
Object show all
Defined in:
lib/imdb_lists.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url) ⇒ ImdbLists



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

#urlObject (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.

Returns:

  • ImdbLists object.



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

#csvObject

Returns String A url to the CVS file.

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?

Returns:

  • (Boolean)

    Boolean Valid?



87
88
89
# File 'lib/imdb_lists.rb', line 87

def is_url_valid?
  !! @url.to_s.match(url_validator)
end

#moviesObject



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

#nameObject

Returns String Name for the given list.

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