Sha256: b666c7b4d7f31e2daeb79e90dda06915f436ef92babd18a282293e7c19e0b747

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

module Ruskino33Parser
  class Movie
    def initialize(movie)
      @movie = movie
    end

    def title
      @movie.search('.film_desc h3').first.text
    end

    def schedules
      result = []
      @movie.search('table.sheet tr').each do |tr|
        next if tr.search('td').first.text == 'Зал'
        result += prepare_schedule(tr.search('td'))
      end
      result
    end

    def other_days
      @movie.search('.other_days a').map do |other_day|
        {
          date: other_day.text,
          url: "http://www.ruskino33.ru#{other_day.attribute('href')}"
        }
      end
    end

    private

    def prepare_schedule(cell)
      cell.last.search('a').map do |time|
        {
          hall: cell.first.text,
          time: "#{time.text}:#{time.next.text}",
          prices: prepare_price(time.attribute('title').text),
          book_url: "http://www.ruskino33.ru#{time.attribute('href')}#session_info"
        }
      end
    end

    def prepare_price(prices)
      prices = prices.split(';').map { |price| price.sub!('руб', '').to_i }
      { vip: prices[0], doble_seat: prices[1], economy: prices[2] }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruskino33_parser-0.1.2 lib/ruskino33_parser/movie.rb