Sha256: dcc6238391401d12eeb98a6c8d6eaa601a927a650976efc7f1d403b11bab9835

Contents?: true

Size: 1.22 KB

Versions: 4

Compression:

Stored size: 1.22 KB

Contents

module CineworldUk
  # Internal utility classes: Do not use
  # @api private
  module Internal
    # Parses a chunk of HTML to derive movie showing data
    class WhatsonParser
      # css selector for film html chunks
      FILM_CSS       = '#filter-reload > .span9 > .row:not(.schedule)'
      # css selector for screenings html chunks
      SCREENINGS_CSS = '#filter-reload > .span9 > .schedule'

      # @param [Integer] cinema_id cineworld cinema id
      def initialize(cinema_id)
        @cinema_id = cinema_id
      end

      # break up the whats on page into individual chunks for each film
      # @return [Array<String>] html chunks for a film and it's screenings
      def films_with_screenings
        films_html.each_with_index.map do |html, i|
          html + screenings_html[i]
        end
      end

      private

      def films_html
        whatson_doc.css(FILM_CSS).map { |n| n.to_s.gsub(/^\s+/, '') }
      end

      def screenings_html
        whatson_doc.css(SCREENINGS_CSS).map { |n| n.to_s.gsub(/^\s+/, '') }
      end

      def whatson
        @whatson ||= CineworldUk::Internal::Website.new.whatson(@cinema_id)
      end

      def whatson_doc
        @whatson_doc ||= Nokogiri::HTML(whatson)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cineworld_uk-2.0.3 lib/cineworld_uk/internal/whatson_parser.rb
cineworld_uk-2.0.2 lib/cineworld_uk/internal/whatson_parser.rb
cineworld_uk-2.0.1 lib/cineworld_uk/internal/whatson_parser.rb
cineworld_uk-2.0.0 lib/cineworld_uk/internal/whatson_parser.rb