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
35
36
37
38
39
# File 'lib/omelete/showtime_agent.rb', line 17

def showtimes
  if @page_doc
    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+/]
      obs = div.css("table tr td[colspan='3']").text
      div.css("table tr[class='even']", "table tr[class='odd']").each do |tr|
        tr.css("td").each_with_index do |td, i|
          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
    end
    showtimes
  else
    nil
  end
end