Sha256: 021c834b6e80ede0e14e377a4953b76543b428167852a97780d303950cc2e9bf

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

module Ruskino33Parser
  class Movie
    # get Nokogiri
    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

2 entries across 2 versions & 1 rubygems

Version Path
ruskino33_parser-0.1.1 lib/ruskino33_parser/movie.rb
ruskino33_parser-0.1.0 lib/ruskino33_parser/movie.rb