omelete 2.0.6 → 2.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,25 +14,29 @@ module Omelete
14
14
  end
15
15
 
16
16
  def movies
17
- movies=[]
18
- omelete_id, name, runtime, genre, age_rating, image = nil, nil, nil, nil, nil, nil
19
- @page_doc.css("div[class='programacao_filme']").each do |m|
20
- omelete_id = m.css("div[class='programacao_filme_desc'] h2").css("a")[0]
21
- omelete_id = omelete_id ? omelete_id["href"][/\d+/] : nil
22
- name = m.css("div[class='programacao_filme_desc'] h2 a").text
23
- movie = MovieInfo.new(omelete_id, name)
17
+ if @page_doc
18
+ movies=[]
19
+ omelete_id, name, runtime, genre, age_rating, image = nil, nil, nil, nil, nil, nil
20
+ @page_doc.css("div[class='programacao_filme']").each do |m|
21
+ omelete_id = m.css("div[class='programacao_filme_desc'] h2").css("a")[0]
22
+ omelete_id = omelete_id ? omelete_id["href"][/\d+/] : nil
23
+ name = m.css("div[class='programacao_filme_desc'] h2 a").text
24
+ movie = MovieInfo.new(omelete_id, name)
24
25
 
25
- image = m.css("div[class='programacao_filme_poster']").css("a")[0]
26
- genre = m.css("div[class='programacao_filme_desc'] h4").text.split(" - ")[0]
27
- movie.runtime = m.css("div[class='programacao_filme_desc'] h4").text.split(" - ")[1]
28
- age_rating = m.css("div[class='programacao_filme_desc'] h4").text.split(" - ")[2]
26
+ image = m.css("div[class='programacao_filme_poster']").css("a")[0]
27
+ genre = m.css("div[class='programacao_filme_desc'] h4").text.split(" - ")[0]
28
+ movie.runtime = m.css("div[class='programacao_filme_desc'] h4").text.split(" - ")[1]
29
+ age_rating = m.css("div[class='programacao_filme_desc'] h4").text.split(" - ")[2]
29
30
 
30
- movie.image = image ? image["href"] : nil
31
- movie.age_rating = age_rating ? age_rating[/\d+/] : nil
31
+ movie.image = image ? image["href"] : nil
32
+ movie.age_rating = age_rating ? age_rating[/\d+/] : nil
32
33
 
33
- movies << movie
34
+ movies << movie
35
+ end
36
+ movies
37
+ else
38
+ nil
34
39
  end
35
- movies
36
40
  end
37
41
 
38
42
  end
@@ -15,17 +15,21 @@ module Omelete
15
15
  end
16
16
 
17
17
  def movie
18
- synopsis, cast, directed_by = nil, nil, nil
19
- movie = MovieInfo.new @id, nil
20
- movie.synopsis = @page_doc.css("div#tab_#{@id}_sinopse blockquote").text
21
- @page_doc.css("div#tab_#{@id}_ficha dl").children.each do |child|
22
- if child.node_name == "dd" && child.previous_element && child.previous_element.content == "Direção:"
23
- movie.directed_by = child.content.delete("\r\n")
24
- elsif child.node_name == "dd" && child.previous_element && child.previous_element.content == "Elenco:"
25
- movie.cast = child.content.delete("\r\n")
18
+ if @page_doc
19
+ synopsis, cast, directed_by = nil, nil, nil
20
+ movie = MovieInfo.new @id, nil
21
+ movie.synopsis = @page_doc.css("div#tab_#{@id}_sinopse blockquote").text
22
+ @page_doc.css("div#tab_#{@id}_ficha dl").children.each do |child|
23
+ if child.node_name == "dd" && child.previous_element && child.previous_element.content == "Direção:"
24
+ movie.directed_by = child.content.delete("\r\n")
25
+ elsif child.node_name == "dd" && child.previous_element && child.previous_element.content == "Elenco:"
26
+ movie.cast = child.content.delete("\r\n")
27
+ end
26
28
  end
29
+ movie
30
+ else
31
+ nil
27
32
  end
28
- movie
29
33
  end
30
34
 
31
35
  end
@@ -15,9 +15,13 @@ module Omelete
15
15
  end
16
16
 
17
17
  def movie_theater
18
- name = @page_doc.css("div[class='programacao_cinema'] h2 a").text
19
- values = @page_doc.css("div#tab_#{@id}_ingressos dl dd").text
20
- @movie_theater = MovieTheaterInfo.new @id, name, values
18
+ if @page_doc
19
+ name = @page_doc.css("div[class='programacao_cinema'] h2 a").text
20
+ values = @page_doc.css("div#tab_#{@id}_ingressos dl dd").text
21
+ @movie_theater = MovieTheaterInfo.new @id, name, values
22
+ else
23
+ nil
24
+ end
21
25
  end
22
26
 
23
27
  end
@@ -15,23 +15,27 @@ module Omelete
15
15
  end
16
16
 
17
17
  def showtimes
18
- showtimes = []
19
- obs, kind, time, theater = nil, nil, nil, nil
20
- @page_doc.css("div[class='programacao_horarios']").each do |div|
21
- omelete_movie_id = div.css("p a")[0]["href"][/\d+/]
22
- obs = div.css("table tr td[colspan='3']").text
23
- div.css("table tr[class='even']", "table tr[class='odd']").each do |tr|
24
- tr.css("td").each_with_index do |td, i|
25
- unless td.attribute("colspan")
26
- theater = td.text if i == 0
27
- kind = td.text if i == 1
28
- time = td.text if i == 2
18
+ if @page_doc
19
+ showtimes = []
20
+ obs, kind, time, theater = nil, nil, nil, nil
21
+ @page_doc.css("div[class='programacao_horarios']").each do |div|
22
+ omelete_movie_id = div.css("p a")[0]["href"][/\d+/]
23
+ obs = div.css("table tr td[colspan='3']").text
24
+ div.css("table tr[class='even']", "table tr[class='odd']").each do |tr|
25
+ tr.css("td").each_with_index do |td, i|
26
+ unless td.attribute("colspan")
27
+ theater = td.text if i == 0
28
+ kind = td.text if i == 1
29
+ time = td.text if i == 2
30
+ end
29
31
  end
32
+ showtimes << ShowtimeInfo.new(omelete_movie_id, obs, kind, time, theater)
30
33
  end
31
- showtimes << ShowtimeInfo.new(omelete_movie_id, obs, kind, time, theater)
32
34
  end
35
+ showtimes
36
+ else
37
+ nil
33
38
  end
34
- showtimes
35
39
  end
36
40
 
37
41
  end
@@ -15,14 +15,18 @@ module Omelete
15
15
  end
16
16
 
17
17
  def theaters
18
- theaters = []
19
- @page_doc.css("div[class='programacao_horarios'] table tr td").each do |td|
20
- if td.text.match(/^[0-9]{1,}$/)
21
- @theater = TheaterInfo.new td.text
22
- theaters << @theater
18
+ if @page_doc
19
+ theaters = []
20
+ @page_doc.css("div[class='programacao_horarios'] table tr td").each do |td|
21
+ if td.text.match(/^[0-9]{1,}$/)
22
+ @theater = TheaterInfo.new td.text
23
+ theaters << @theater
24
+ end
23
25
  end
26
+ theaters
27
+ else
28
+ nil
24
29
  end
25
- theaters
26
30
  end
27
31
 
28
32
  end
data/lib/omelete.rb CHANGED
@@ -25,22 +25,22 @@ module Omelete
25
25
  begin
26
26
  uri = URI.escape(HOME_URL + complement)
27
27
  @page_doc = Nokogiri::HTML(open(uri))
28
- @page_doc
29
28
  rescue => e
30
29
  case e
31
30
  when OpenURI::HTTPError
32
- p "OpenURI::HTTPError"
31
+ p "OpenURI::HTTPError on: #{HOME_URL + complement}"
33
32
  when SocketError
34
- p "SocketError"
33
+ p "SocketError on: #{HOME_URL + complement}"
35
34
  end
36
- raise e.message
35
+ @page_doc = nil
37
36
  rescue SystemCallError => e
38
37
  if e === Errno::ECONNRESET
39
- p "SystemCallError"
38
+ p "SystemCallError on: #{HOME_URL + complement}"
40
39
  end
41
- raise e.message
40
+ @page_doc = nil
42
41
  end
43
- end
42
+ @page_doc
43
+ end
44
44
 
45
45
  end
46
46
  end
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Omelete
2
- VERSION = "2.0.6"
2
+ VERSION = "2.0.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omelete
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.6
4
+ version: 2.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: