Sha256: d9de00df83ff2939dd4d383aca38c3e54ab08e8a18ba76058e501c743d189b14
Contents?: true
Size: 1.56 KB
Versions: 1
Compression:
Stored size: 1.56 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 FilmWithScreeningsParser # css selector for film name link FILM_NAME_CSS = 'h3.h1' # css selector for performances PERFORMANCES_CSS = '.schedule .performances > li' # @param [String] film_html a chunk of html def initialize(film_html) @film_html = film_html.to_s end # The film name # @return [String] def film_name title_sanitizer(film_name_text.children[0].to_s) end # attributes of all the screenings # @return [Array<Hash>] def to_a performances_doc.map do |node| next unless screening_parser_hash(node) screening_parser_hash(node).merge(film_hash) end.compact end private def doc @doc ||= Nokogiri::HTML(@film_html) end def film_hash @film_hash ||= { film_name: film_name } end def film_link @film_link ||= film_name_doc.css('a[href*=whatson]') end def film_name_text film_link.empty? ? name_doc : film_link end def film_name_doc @film_name_doc ||= doc.css(FILM_NAME_CSS) end def performances_doc @performances_doc ||= doc.css(PERFORMANCES_CSS) end def screening_parser_hash(node) ScreeningParser.new(node).to_hash end def title_sanitizer(title) TitleSanitizer.new(title).sanitized end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
cineworld_uk-2.1.0 | lib/cineworld_uk/internal/film_with_screenings_parser.rb |