Class: IMDbWatchlist
- Inherits:
-
Object
- Object
- IMDbWatchlist
- Defined in:
- lib/imdb_watchlist.rb
Defined Under Namespace
Classes: Item
Instance Attribute Summary collapse
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(url) ⇒ IMDbWatchlist
constructor
A new instance of IMDbWatchlist.
- #sanitize_url(url) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(url) ⇒ IMDbWatchlist
Returns a new instance of IMDbWatchlist.
27 28 29 30 31 32 33 34 35 |
# File 'lib/imdb_watchlist.rb', line 27 def initialize(url) @url = url open(sanitize_url(url)) do |rss| feed = RSS::Parser.parse(rss) @title = feed.channel.title @items = feed.items.map { |feed_item| Item.new(feed_item) } end end |
Instance Attribute Details
#items ⇒ Object (readonly)
Returns the value of attribute items.
25 26 27 |
# File 'lib/imdb_watchlist.rb', line 25 def items @items end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
24 25 26 |
# File 'lib/imdb_watchlist.rb', line 24 def title @title end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
23 24 25 |
# File 'lib/imdb_watchlist.rb', line 23 def url @url end |
Instance Method Details
#sanitize_url(url) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/imdb_watchlist.rb', line 37 def sanitize_url(url) uri = URI(url) # No scheme? Probably a local file path. if uri.scheme == nil return url end # Verify host if not uri.host.end_with? 'imdb.com' raise "Must provide an 'imdb.com' URL '#{url}" end # Verify path path_matches = /user\/(ur\d+)\/watchlist/.match(uri.path) if not path_matches raise "Must provide a watchlist URL '#{url}'" end # Require RSS subdomain uri.host = 'rss.imdb.com' uri.to_s end |
#to_s ⇒ Object
62 63 64 |
# File 'lib/imdb_watchlist.rb', line 62 def to_s "#{title} - #{url} - #{items.count} Items" end |