Class: Omelete::ShowtimeAgent

Inherits:
Object
  • Object
show all
Defined in:
lib/omelete/showtime_agent.rb

Instance Method Summary collapse

Constructor Details

#initialize(omelete_id) ⇒ ShowtimeAgent

Returns a new instance of ShowtimeAgent.



11
12
13
14
15
# File 'lib/omelete/showtime_agent.rb', line 11

def initialize(omelete_id)
  client = Client.new
  @id = omelete_id
  @page_doc = client.page_doc("cinema/#{@id}")
end

Instance Method Details

#showtimesObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/omelete/showtime_agent.rb', line 17

def showtimes
  showtimes = []
  obs, kind, time, theater = nil, nil, nil, nil
  @page_doc.css("div[class='programacao_horarios']").each do |div|
    omelete_movie_id = div.css("p a")[0]["href"][/\d+/]
    div.css("table tr td").each_with_index do |td, i|
      obs = td.text if td.attribute("colspan")
      unless td.attribute("colspan")
        theater = td.text if i == 0
        kind = td.text if i == 1
        time = td.text if i == 2
      end
    end
    
    showtimes << ShowtimeInfo.new(omelete_movie_id, obs, kind, time, theater)
  end
  showtimes
end