Class: FilmAffinity::Movie
- Inherits:
-
Object
- Object
- FilmAffinity::Movie
- Defined in:
- lib/filmaffinity/movie.rb
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
Instance Method Summary collapse
- #cast ⇒ Object
- #company ⇒ Object
- #country ⇒ Object
- #director ⇒ Object
- #document_html ⇒ Object
- #duration ⇒ Object
- #generate_html ⇒ Object
- #genres ⇒ Object
-
#initialize(id, title = nil) ⇒ Movie
constructor
A new instance of Movie.
- #music ⇒ Object
- #photography ⇒ Object
- #poster ⇒ Object
- #poster_big ⇒ Object
- #rating ⇒ Object
- #script ⇒ Object
- #sinopsis ⇒ Object
- #to_json ⇒ Object
- #year ⇒ Object
Constructor Details
#initialize(id, title = nil) ⇒ Movie
Returns a new instance of Movie.
4 5 6 7 8 9 |
# 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 |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/filmaffinity/movie.rb', line 3 def id @id end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
3 4 5 |
# File 'lib/filmaffinity/movie.rb', line 3 def title @title end |
Instance Method Details
#cast ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# 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 ⇒ Object
57 58 59 60 61 |
# File 'lib/filmaffinity/movie.rb', line 57 def company document_html.at(Constants.tag(:company)).next_sibling.next_sibling.content rescue nil end |
#country ⇒ Object
37 38 39 40 41 42 |
# 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 ⇒ Object
44 45 46 47 48 49 |
# 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 ⇒ Object
11 12 13 |
# File 'lib/filmaffinity/movie.rb', line 11 def document_html @document_html ||= Nokogiri::HTML(generate_html) end |
#duration ⇒ Object
31 32 33 34 35 |
# File 'lib/filmaffinity/movie.rb', line 31 def duration document_html.at(Constants.tag(:duration)).content[/\d+/].to_i rescue nil end |
#generate_html ⇒ Object
15 16 17 |
# File 'lib/filmaffinity/movie.rb', line 15 def generate_html open(Constants.urls[:movie] % id) end |
#genres ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 |
# 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 ⇒ Object
51 52 53 54 55 |
# File 'lib/filmaffinity/movie.rb', line 51 def music document_html.at(Constants.tag(:music)).next_sibling.next_sibling.content rescue nil end |
#photography ⇒ Object
69 70 71 72 73 |
# File 'lib/filmaffinity/movie.rb', line 69 def photography document_html.at(Constants.tag(:photography)).next_sibling.next_sibling.content rescue nil end |
#poster ⇒ Object
111 112 113 114 115 116 |
# 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 ⇒ Object
118 119 120 121 122 123 |
# 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 ⇒ Object
104 105 106 107 108 109 |
# File 'lib/filmaffinity/movie.rb', line 104 def = document_html.at(Constants.tag(:rating)).content.strip .tr(',', '.').to_f if rescue nil end |
#script ⇒ Object
63 64 65 66 67 |
# File 'lib/filmaffinity/movie.rb', line 63 def script document_html.at(Constants.tag(:script)).next_sibling.next_sibling.content rescue nil end |
#sinopsis ⇒ Object
98 99 100 101 102 |
# File 'lib/filmaffinity/movie.rb', line 98 def sinopsis document_html.at(Constants.tag(:sinopsis)).content rescue nil end |
#to_json ⇒ Object
125 126 127 |
# File 'lib/filmaffinity/movie.rb', line 125 def to_json @json_parser.to_json self end |