class FilmAffinity::Movie
Attributes
id[R]
title[R]
Public Class Methods
new(id, title = nil)
click to toggle source
# File lib/filmaffinity/movie.rb, line 4 def initialize(id, title = nil) @id = id @title = title if title @json_parser = JsonMovieParser.new @poster_manager = PosterManager.new end
Public Instance Methods
cast()
click to toggle source
# File lib/filmaffinity/movie.rb, line 75 def cast actors = [] node = document_html.search(Constants.tag(:cast)) node.each do |actor| actors << actor.at(Constants.tag(:cast_each)).content.strip end actors rescue [] end
company()
click to toggle source
# File lib/filmaffinity/movie.rb, line 57 def company document_html.at(Constants.tag(:company)).next_sibling.next_sibling.content rescue nil end
country()
click to toggle source
# File lib/filmaffinity/movie.rb, line 37 def country raw_country = document_html.at(Constants.tag(:country)).next_sibling.content raw_country.gsub(/\A[[:space:]]+|[[:space:]]+\z/, '') if raw_country rescue nil end
director()
click to toggle source
# File lib/filmaffinity/movie.rb, line 44 def director raw_director = document_html.at(Constants.tag(:director)).content raw_director.strip if raw_director rescue nil end
document_html()
click to toggle source
# File lib/filmaffinity/movie.rb, line 11 def document_html @document_html ||= Nokogiri::HTML(generate_html) end
duration()
click to toggle source
# File lib/filmaffinity/movie.rb, line 31 def duration document_html.at(Constants.tag(:duration)).content[/\d+/].to_i rescue nil end
generate_html()
click to toggle source
# File lib/filmaffinity/movie.rb, line 15 def generate_html open(Constants.urls[:movie] % id) end
genres()
click to toggle source
# File lib/filmaffinity/movie.rb, line 86 def genres genres = [] node = document_html.at(Constants.tag(:genre)).next_sibling.next_sibling raw_genres = node.search('a') raw_genres.each do |raw_genre| genres << raw_genre.content.strip end genres rescue [] end
music()
click to toggle source
# File lib/filmaffinity/movie.rb, line 51 def music document_html.at(Constants.tag(:music)).next_sibling.next_sibling.content rescue nil end
photography()
click to toggle source
# File lib/filmaffinity/movie.rb, line 69 def photography document_html.at(Constants.tag(:photography)).next_sibling.next_sibling.content rescue nil end
poster()
click to toggle source
# File lib/filmaffinity/movie.rb, line 111 def poster poster_url = document_html.at(Constants.tag(:poster))['src'] @poster_manager.load_poster(poster_url) if poster_url rescue nil end
poster_big()
click to toggle source
# File lib/filmaffinity/movie.rb, line 118 def poster_big poster_url = document_html.at(Constants.tag(:poster_big))['href'] @poster_manager.load_poster(poster_url) if poster_url rescue nil end
rating()
click to toggle source
# File lib/filmaffinity/movie.rb, line 104 def rating raw_rating = document_html.at(Constants.tag(:rating)).content.strip raw_rating.tr(',', '.').to_f if raw_rating rescue nil end
script()
click to toggle source
# File lib/filmaffinity/movie.rb, line 63 def script document_html.at(Constants.tag(:script)).next_sibling.next_sibling.content rescue nil end
sinopsis()
click to toggle source
# File lib/filmaffinity/movie.rb, line 98 def sinopsis document_html.at(Constants.tag(:sinopsis)).content rescue nil end
to_json()
click to toggle source
# File lib/filmaffinity/movie.rb, line 125 def to_json @json_parser.to_json self end
year()
click to toggle source
# File lib/filmaffinity/movie.rb, line 25 def year document_html.at(Constants.tag(:year)).content[/\d+/].to_i rescue nil end